diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index 3420249e7..833636af9 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -6,6 +6,9 @@ class ProductBuildList < ActiveRecord::Base include AbfWorker::ModelHelper 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_FAILED = 1 BUILD_PENDING = 2 @@ -65,6 +68,8 @@ class ProductBuildList < ActiveRecord::Base 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 :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 before_destroy :can_destroy? diff --git a/config/schedule.rb b/config/schedule.rb index 92d28d47c..318eabf95 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -7,19 +7,23 @@ # runner "Download.parse_and_remove_nginx_log" #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' 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' 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' 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' end diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/tasks/product_build_list.rake b/lib/tasks/product_build_list.rake new file mode 100644 index 000000000..892f7e343 --- /dev/null +++ b/lib/tasks/product_build_list.rake @@ -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