#31: add task for removing outdated ProductBuildLists

This commit is contained in:
Vokhmin Alexey V 2013-03-22 22:18:54 +04:00
parent e528127f85
commit 1fc21448ce
4 changed files with 27 additions and 4 deletions

View File

@ -6,6 +6,9 @@ class ProductBuildList < ActiveRecord::Base
include AbfWorker::ModelHelper include AbfWorker::ModelHelper
delegate :url_helpers, to: 'Rails.application.routes' delegate :url_helpers, to: 'Rails.application.routes'
LIVE_TIME = 2.week # for autostart
MAX_LIVE_TIME = 3.month # for manual start;
BUILD_COMPLETED = 0 BUILD_COMPLETED = 0
BUILD_FAILED = 1 BUILD_FAILED = 1
BUILD_PENDING = 2 BUILD_PENDING = 2
@ -65,6 +68,8 @@ class ProductBuildList < ActiveRecord::Base
scope :for_user, lambda { |user| where(:user_id => user.id) } scope :for_user, lambda { |user| where(:user_id => user.id) }
scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")} scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")}
scope :recent, order("#{table_name}.updated_at DESC") scope :recent, order("#{table_name}.updated_at DESC")
scope :outdated, where(:not_delete => false).
where("(#{table_name}.created_at < ? AND #{table_name}.autostarted is TRUE) OR #{table_name}.created_at < ?", Time.now - LIVE_TIME, Time.now - MAX_LIVE_TIME)
after_create :add_job_to_abf_worker_queue after_create :add_job_to_abf_worker_queue
before_destroy :can_destroy? before_destroy :can_destroy?

View File

@ -7,19 +7,23 @@
# runner "Download.parse_and_remove_nginx_log" # runner "Download.parse_and_remove_nginx_log"
#end #end
every 1.day, :at => '4:00 am' do every :day, :at => '4:10 am' do
rake "product_build_list:clear:outdated", :output => 'log/product_build_list_clear.log'
end
every :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 every :day, :at => '3:50 am' do
rake "buildlist:clear:outdated", :output => 'log/build_list_clear.log' rake "buildlist:clear:outdated", :output => 'log/build_list_clear.log'
end end
every 1.day, :at => '3:30 am' do every :day, :at => '3:30 am' do
rake "pull_requests:clear", :output => 'log/pull_requests_clear.log' rake "pull_requests:clear", :output => 'log/pull_requests_clear.log'
end end
every 1.day, :at => '3:00 am' do every :day, :at => '3:00 am' do
rake "activity_feeds:clear", :output => 'log/activity_feeds.log' rake "activity_feeds:clear", :output => 'log/activity_feeds.log'
end end

View File

View File

@ -0,0 +1,14 @@
namespace :product_build_list do
namespace :clear do
desc 'Remove outdated ProductBuildLists'
task :outdated => :environment do
say "[#{Time.zone.now}] Removing outdated ProductBuildLists"
say "[#{Time.zone.now}] There are #{ProductBuildList.outdated.count} outdated ProductBuildLists"
ProductBuildList.outdated.destroy_all
say "[#{Time.zone.now}] Outdated BuildLists have been removed"
end
end
end