diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 12779db0a..4d6cefaf2 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,9 +91,11 @@ 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 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..ea6a40eff --- /dev/null +++ b/lib/tasks/buildlist.rake @@ -0,0 +1,16 @@ + +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}" + + BuildList.outdated.destroy_all + + say "Outdated BuildLists was successfully removed" + end + end +end