[issue #430] Added rake task to remove outdated BuildLists.

This commit is contained in:
George Vinogradov 2012-05-11 21:44:19 +04:00
parent f2c72ba342
commit 1a9f529152
3 changed files with 33 additions and 3 deletions

View File

@ -23,6 +23,8 @@ class BuildList < ActiveRecord::Base
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id
} }
LIVE_TIME = 3.week
# The kernel does not send these statuses directly # The kernel does not send these statuses directly
BUILD_CANCELED = 5000 BUILD_CANCELED = 5000
WAITING_FOR_RESPONSE = 4000 WAITING_FOR_RESPONSE = 4000
@ -89,15 +91,19 @@ class BuildList < ActiveRecord::Base
} }
scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")} scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")}
scope :outdated, where('updated_at < ? AND status <> ?', Time.now - LIVE_TIME, BUILD_PUBLISHED)
serialize :additional_repos serialize :additional_repos
serialize :include_repos serialize :include_repos
before_create :set_default_status before_create :set_default_status
after_create :place_build after_create :place_build
def self.human_status(status) class << self
def human_status(status)
I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}")
end end
end
def human_status def human_status
self.class.human_status(status) self.class.human_status(status)

View File

@ -10,3 +10,7 @@
every 1.day, :at => '4:00 am' do every 1.day, :at => '4:00 am' do
rake "import:sync:all", :output => 'log/sync.log' rake "import:sync:all", :output => 'log/sync.log'
end end
every 1.day, :at => '3:50 am' do
rake "buildlist:clear:outdated", :output => 'log/build_list_clear.log'
end

20
lib/tasks/buildlist.rake Normal file
View File

@ -0,0 +1,20 @@
namespace :buildlist do
namespace :clear do
desc 'Remove outdated unpublished BuildLists'
task :outdated => :environment do
say "Removing outdated BuildLists"
outdated = BuildList.outdated
say "There are #{outdated.count} outdated BuildLists at #{Time.now}"
begin
BuildList.outdated.map(&:destroy)
rescue Exception => e
say "There was an error: #{e.message}"
end
say "Outdated BuildLists was successfully removed"
end
end
end