Merge branch 'master' of abf.rosalinux.ru:abf/rosa-build

This commit is contained in:
Alexander Machehin 2015-03-12 15:57:36 +05:00
commit aed389a7ad
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?
}
scope :scoped_to_new_core, ->(new_core) { where(new_core: new_core) }
scope :outdated, -> {
where("#{table_name}.created_at < ? AND #{table_name}.status NOT IN (?) OR #{table_name}.created_at < ?",
Time.now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], Time.now - MAX_LIVE_TIME)
scope :outdated, -> (now = Time.now) {
where(<<-SQL, now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], 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) }

View File

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