rosa-build/app/jobs/remove_outdated_items_job.rb

27 lines
912 B
Ruby
Raw Normal View History

2016-05-28 19:21:02 +01:00
class RemoveOutdatedItemsJob < BaseActiveRecordJob
include Sidekiq::Worker
sidekiq_options :queue => :low
2016-05-28 19:21:02 +01:00
def perform_with_ar_connection
log_file = Rails.root.join("log", "remove_outdated.log").to_s
counter_bl = 0
BuildList.outdated.find_each(batch_size: 100) do |bl|
bl.destroy && (counter_bl += 1) if bl.id != bl.last_published.first.try(:id)
end
counter_mb = 0
MassBuild.outdated.find_each do |mb|
mb.destroy && (counter_mb += 1) if mb.build_lists.count == 0
end
counter_pbl = ProductBuildList.outdated.count
ProductBuildList.outdated.destroy_all
2016-05-03 19:04:24 +01:00
User.find_each(batch_size: 50) do |u|
u.activity_feeds.outdated.destroy_all
end
File.open(log_file, "w") do |f|
f.puts "Build Lists deleted: #{counter_bl}"
f.puts "Mass Builds deleted: #{counter_mb}"
f.puts "Product Build Lists deleted: #{counter_pbl}"
end
end
2016-05-03 19:04:24 +01:00
end