Merge branch '8784-dir-listings'
[arvados.git] / services / api / lib / tasks / delete_old_job_logs.rake
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
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.
8
9 namespace :db do
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')"
13
14     ActiveRecord::Base.connection.execute(delete_sql)
15   end
16 end