#463: Increased life time for builds of mass builds

This commit is contained in:
Vokhmin Alexey V 2015-03-11 02:43:58 +03:00
parent ba84f0f916
commit e599be5828
2 changed files with 14 additions and 9 deletions

View File

@ -154,9 +154,16 @@ class BuildList < ActiveRecord::Base
joins(:project).where('projects.name LIKE ?', "%#{project_name}%") if project_name.present? joins(:project).where('projects.name LIKE ?', "%#{project_name}%") if project_name.present?
} }
scope :scoped_to_new_core, ->(new_core) { where(new_core: new_core) } scope :scoped_to_new_core, ->(new_core) { where(new_core: new_core) }
scope :outdated, -> { scope :outdated, -> (now = Time.now) {
where("#{table_name}.created_at < ? AND #{table_name}.status NOT IN (?) OR #{table_name}.created_at < ?", where(<<-SQL, now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], now - MAX_LIVE_TIME)
Time.now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], Time.now - MAX_LIVE_TIME) (
#{table_name}.created_at < ? AND
#{table_name}.status NOT IN (?) AND
#{table_name}.mass_build_id IS NULL
) OR (
#{table_name}.created_at < ?
)
SQL
} }
scope :published_container, -> { where(container_status: BUILD_PUBLISHED) } scope :published_container, -> { where(container_status: BUILD_PUBLISHED) }

View File

@ -7,17 +7,15 @@ namespace :buildlist do
say "[#{Time.zone.now}] Removing outdated BuildLists" say "[#{Time.zone.now}] Removing outdated BuildLists"
say "[#{Time.zone.now}] There are #{BuildList.outdated.count} outdated BuildLists" say "[#{Time.zone.now}] There are #{BuildList.outdated.count} outdated BuildLists"
counter = 0 counter = 0
BuildList.outdated.order(:id).find_in_batches(batch_size: 100) do |build_lists| BuildList.outdated.find_each(batch_size: 100) do |bl|
build_lists.each do |bl|
bl.destroy && (counter += 1) if bl.id != bl.last_published.first.try(:id) bl.destroy && (counter += 1) if bl.id != bl.last_published.first.try(:id)
end end
end
say "[#{Time.zone.now}] #{counter} outdated BuildLists have been removed" say "[#{Time.zone.now}] #{counter} outdated BuildLists have been removed"
say "[#{Time.zone.now}] Removing outdated MassBuilds" say "[#{Time.zone.now}] Removing outdated MassBuilds"
say "[#{Time.zone.now}] There are #{MassBuild.outdated.count} outdated MassBuilds" say "[#{Time.zone.now}] There are #{MassBuild.outdated.count} outdated MassBuilds"
counter = 0 counter = 0
MassBuild.outdated.each do |mb| MassBuild.outdated.find_each do |mb|
mb.destroy && (counter += 1) if mb.build_lists.count == 0 mb.destroy && (counter += 1) if mb.build_lists.count == 0
end end
say "[#{Time.zone.now}] #{counter} outdated MassBuilds have been removed" say "[#{Time.zone.now}] #{counter} outdated MassBuilds have been removed"