1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 # This task finds jobs that have been finished for at least as long as
6 # the duration specified in the `clean_job_log_rows_after`
7 # configuration setting, and deletes their stderr logs from the logs table.
10 desc "Remove old job stderr entries from the logs table"
11 task delete_old_job_logs: :environment do
12 delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN jobs ON logs.object_uuid = jobs.uuid WHERE event_type = 'stderr' AND jobs.log IS NOT NULL AND clock_timestamp() - jobs.finished_at > interval '#{Rails.configuration.clean_job_log_rows_after} seconds')"
14 ActiveRecord::Base.connection.execute(delete_sql)