1 # This task finds jobs that have been finished for at least as long as
2 # the duration specified in the `clean_job_log_rows_after`
3 # configuration setting, and deletes their stderr logs from the logs table.
6 desc "Remove old job stderr entries from the logs table"
7 task delete_old_job_logs: :environment do
9 joins("JOIN jobs ON object_uuid = jobs.uuid").
10 where("event_type = :etype AND jobs.log IS NOT NULL AND jobs.finished_at < :age",
12 age: Rails.configuration.clean_job_log_rows_after.ago).
13 find_in_batches do |old_log_ids|
14 Log.where(id: old_log_ids.map(&:id)).delete_all