#430: Cleans old RPM buildroots from BuildLists

This commit is contained in:
Vokhmin Alexey V 2014-09-26 23:51:28 +04:00
parent ccdf968f60
commit 28618a8d68
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,30 @@
module BuildLists
class CleanBuildrootJob
@queue = :middle
FILENAME = 'rpm-buildroot.tar.gz'
def self.perform
build_lists = BuildList.where(save_buildroot: true).
where('updated_at < ?', Time.now - 1.hour).
where('results ~ ?', "file_name: #{FILENAME}")
build_lists.find_each do |build_list|
buildroots = build_list.results.select do |r|
r['file_name'] == FILENAME
end
build_list.results -= buildroots
build_list.save(validate: false)
clean_file_store buildroots
end
end
def self.clean_file_store(buildroots)
buildroots.each do |r|
FileStoreService::File.new(sha1: r['sha1']).destroy
end
end
end
end

View File

@ -26,6 +26,13 @@ clean_api_defender_statistics:
queue: low
description: 'Cleans ApiDefender statistics'
clean_build_list_buildroot:
every:
- '1h'
class: 'BuildLists::CleanBuildrootJob'
queue: middle
description: 'Cleans RPM buildroot from BuildList'
run_extra_mass_builds:
every:
- '5m'

View File

@ -0,0 +1,38 @@
require 'spec_helper'
describe BuildLists::CleanBuildrootJob do
before { stub_symlink_methods }
subject { BuildLists::CleanBuildrootJob }
it 'ensures that not raises error' do
FactoryGirl.create(:build_list)
expect(FileStoreService::File).to_not receive(:new)
expect do
subject.perform
end.to_not raise_exception
end
it 'cleans RPM buildroot' do
results = [
{ 'sha1' => 'sha1-1', 'file_name' => BuildLists::CleanBuildrootJob::FILENAME },
{ 'sha1' => 'sha1-2', 'file_name' => 'test.log' }
]
FactoryGirl.create(:build_list,
results: results,
save_buildroot: true
)
bl = FactoryGirl.create(:build_list,
results: results,
save_buildroot: true,
updated_at: Time.now - 2.hours
)
file_store_service = double(:file_store_service, destroy: true)
expect(FileStoreService::File).to receive(:new).with(sha1: 'sha1-1').and_return(file_store_service)
subject.perform
expect(bl.reload.results).to eq [{ 'sha1' => 'sha1-2', 'file_name' => 'test.log' }]
end
end