rosa-build/app/jobs/build_lists/clean_buildroot_job.rb

34 lines
870 B
Ruby
Raw Normal View History

module BuildLists
2016-05-28 19:21:02 +01:00
class CleanBuildrootJob < BaseActiveRecordJob
include Sidekiq::Worker
sidekiq_options :queue => :middle
FILENAME = 'rpm-buildroot.tar.gz'
2016-05-28 19:21:02 +01:00
def perform_with_ar_connection
build_lists = BuildList.where(save_buildroot: true).
for_status(BuildList::BUILD_ERROR).
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
2016-05-28 19:21:02 +01:00
private
def clean_file_store(buildroots)
buildroots.each do |r|
FileStoreService::File.new(sha1: r['sha1']).destroy
end
end
end
end