Merge pull request #605 from warpc/#604-Remove_old_buildlist_created_more_than_3_month_ago

#604 remove outdated buildlists
This commit is contained in:
Alexander Machehin 2012-08-07 02:07:21 -07:00
commit 963b80cc93
5 changed files with 31 additions and 25 deletions

View File

@ -28,7 +28,8 @@ class BuildList < ActiveRecord::Base
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) unless save_to_repository_id.in? save_to_platform.repositories.map(&:id)
}
LIVE_TIME = 3.week
LIVE_TIME = 4.week # for unpublished
MAX_LIVE_TIME = 3.month # for published
# The kernel does not send these statuses directly
BUILD_CANCELED = 5000
@ -97,7 +98,7 @@ class BuildList < ActiveRecord::Base
s
}
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)
scope :outdated, where('created_at < ? AND status <> ? OR created_at < ?', Time.now - LIVE_TIME, BUILD_PUBLISHED, Time.now - MAX_LIVE_TIME)
serialize :additional_repos
serialize :include_repos

View File

@ -4,6 +4,7 @@ class MassBuild < ActiveRecord::Base
has_many :build_lists, :dependent => :destroy
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
scope :outdated, where('created_at < ?', Time.now + 1.day - BuildList::MAX_LIVE_TIME)
attr_accessor :repositories, :arches
attr_accessible :repositories, :arches, :auto_publish

View File

@ -89,7 +89,8 @@ class Project < ActiveRecord::Base
# If main does not exist, will connect only project platform repository
# If project platform repository is main, only main will be connect
main_rep_id = platform.repositories.find_by_name('main').id
build_reps_ids = ([main_rep_id] + [repository_id]).compact.uniq
build_reps_ids = [main_rep_id, repository_id].compact.uniq
arch = Arch.find_by_name(arch) if arch.acts_like?(:string)
build_lists.create do |bl|
bl.save_to_platform = platform

View File

@ -107,8 +107,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
t.integer "project_id"
t.integer "arch_id"
t.datetime "notified_at"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "is_circle", :default => false
t.text "additional_repos"
t.string "name"
@ -138,8 +138,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
t.string "commentable_type"
t.integer "user_id"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.decimal "commentable_id", :precision => 50, :scale => 0
t.integer "project_id"
end
@ -156,8 +156,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
t.string "controller"
t.string "action"
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "flash_notifies", :force => true do |t|
@ -248,8 +248,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
t.string "description"
t.string "name", :null => false
t.integer "parent_platform_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "released", :default => false, :null => false
t.integer "owner_id"
t.string "owner_type"
@ -398,8 +398,7 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"

View File

@ -2,15 +2,19 @@
namespace :buildlist do
namespace :clear do
desc 'Remove outdated unpublished BuildLists'
desc 'Remove outdated BuildLists and MassBuilds'
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"
say "Removing outdated MassBuilds"
outdated = MassBuild.outdated
say "There are #{outdated.count} outdated MassBuilds at #{Time.now}"
MassBuild.outdated.destroy_all
say "Outdated BuildLists and MassBuilds was successfully removed"
end
end
end