From dabd91b2c8a42ac0d0c357190002a5a4b96a57a6 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Thu, 13 Jun 2019 23:07:59 +0200 Subject: Add rake task to clean orphan artifact files This adds the rake task rake gitlab:cleanup:orphan_job_artifact_files. This rake task cleans all orphan job artifact files it can find on disk. It performs a search on the complete folder of all artifacts on disk. Then it filters out all the job artifact ID for which it could not find a record with matching ID in the database. For these, the file is deleted from disk. --- spec/tasks/gitlab/cleanup_rake_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'spec/tasks') diff --git a/spec/tasks/gitlab/cleanup_rake_spec.rb b/spec/tasks/gitlab/cleanup_rake_spec.rb index 19794227d9f..92c094f08a4 100644 --- a/spec/tasks/gitlab/cleanup_rake_spec.rb +++ b/spec/tasks/gitlab/cleanup_rake_spec.rb @@ -156,4 +156,33 @@ describe 'gitlab:cleanup rake tasks' do end end end + + describe 'gitlab:cleanup:orphan_job_artifact_files' do + subject(:rake_task) { run_rake_task('gitlab:cleanup:orphan_job_artifact_files') } + + it 'runs the task without errors' do + expect(Gitlab::Cleanup::OrphanJobArtifactFiles) + .to receive(:new).and_call_original + + expect { rake_task }.not_to raise_error + end + + context 'with DRY_RUN set to false' do + before do + stub_env('DRY_RUN', 'false') + end + + it 'passes dry_run correctly' do + expect(Gitlab::Cleanup::OrphanJobArtifactFiles) + .to receive(:new) + .with(limit: anything, + dry_run: false, + niceness: anything, + logger: anything) + .and_call_original + + rake_task + end + end + end end -- cgit v1.2.3