From 1a9f52915283d98a3566aeaa9029269deef6bfcc Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 11 May 2012 21:44:19 +0400 Subject: [PATCH 1/2] [issue #430] Added rake task to remove outdated BuildLists. --- app/models/build_list.rb | 12 +++++++++--- config/schedule.rb | 4 ++++ lib/tasks/buildlist.rake | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/buildlist.rake diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 12779db0a..e0ba5bc7c 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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 } + LIVE_TIME = 3.week + # The kernel does not send these statuses directly BUILD_CANCELED = 5000 WAITING_FOR_RESPONSE = 4000 @@ -89,14 +91,18 @@ class BuildList < ActiveRecord::Base } 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 :include_repos - + before_create :set_default_status after_create :place_build - def self.human_status(status) - I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") + class << self + def human_status(status) + I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") + end end def human_status diff --git a/config/schedule.rb b/config/schedule.rb index 69ec02b5d..85a3bd556 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -10,3 +10,7 @@ every 1.day, :at => '4:00 am' do rake "import:sync:all", :output => 'log/sync.log' end + +every 1.day, :at => '3:50 am' do + rake "buildlist:clear:outdated", :output => 'log/build_list_clear.log' +end diff --git a/lib/tasks/buildlist.rake b/lib/tasks/buildlist.rake new file mode 100644 index 000000000..080f97818 --- /dev/null +++ b/lib/tasks/buildlist.rake @@ -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 From b74dd01262d69c3968035e8b8bf00d64c03ce806 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 11 May 2012 22:00:27 +0400 Subject: [PATCH 2/2] [issue #430] Changed task --- app/models/build_list.rb | 6 ++---- lib/tasks/buildlist.rake | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index e0ba5bc7c..4d6cefaf2 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -99,10 +99,8 @@ class BuildList < ActiveRecord::Base before_create :set_default_status after_create :place_build - class << self - def human_status(status) - I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") - end + def self.human_status(status) + I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end def human_status diff --git a/lib/tasks/buildlist.rake b/lib/tasks/buildlist.rake index 080f97818..ea6a40eff 100644 --- a/lib/tasks/buildlist.rake +++ b/lib/tasks/buildlist.rake @@ -8,11 +8,7 @@ namespace :buildlist do 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 + BuildList.outdated.destroy_all say "Outdated BuildLists was successfully removed" end