Merge branch 'crunch-job_finds_newer_docker_hashes' of https://github.com/tmooney...
[arvados.git] / services / api / lib / tasks / delete_old_container_logs.rake
1 # This task finds containers that have been finished for at least as long as
2 # the duration specified in the `clean_container_log_rows_after` config setting,
3 # and deletes their stdout, stderr, arv-mount, crunch-run, and  crunchstat logs
4 # from the logs table.
5
6 namespace :db do
7   desc "Remove old container log entries from the logs table"
8
9   task delete_old_container_logs: :environment do
10     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 containers.finished_at < '#{Rails.configuration.clean_container_log_rows_after.ago}')"
11
12     ActiveRecord::Base.connection.execute(delete_sql)
13   end
14 end