2411: Add copyright notices to everything.
[arvados.git] / services / api / lib / tasks / delete_old_container_logs.rake
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 # This task finds containers that have been finished for at least as long as
6 # the duration specified in the `clean_container_log_rows_after` config setting,
7 # and deletes their stdout, stderr, arv-mount, crunch-run, and  crunchstat logs
8 # from the logs table.
9
10 namespace :db do
11   desc "Remove old container log entries from the logs table"
12
13   task delete_old_container_logs: :environment do
14     delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN containers ON logs.object_uuid = containers.uuid WHERE event_type IN ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat') AND containers.log IS NOT NULL AND clock_timestamp() - containers.finished_at > interval '#{Rails.configuration.clean_container_log_rows_after} seconds')"
15
16     ActiveRecord::Base.connection.execute(delete_sql)
17   end
18 end