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