[refs #570] Add mass build counters logs

This commit is contained in:
konstantin.grabar 2012-07-26 15:45:23 +04:00
parent 91dddd5dac
commit f9b217379d
5 changed files with 54 additions and 16 deletions

View File

@ -9,6 +9,7 @@ class BuildList < ActiveRecord::Base
belongs_to :mass_build, :counter_cache => true
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
has_many :counters_logs, :dependent => :destroy
UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage]
RELEASE_UPDATE_TYPES = %w[security bugfix]
@ -100,6 +101,8 @@ class BuildList < ActiveRecord::Base
after_commit :place_build
after_destroy :delete_container
after_create lambda { |build_list| build_list.counters_logs.create(:status => build_list.status, :event => "create", :mass_build_id => build_list.mass_build_id) }
@queue = :clone_and_build
state_machine :status, :initial => :waiting_for_response do
@ -108,12 +111,14 @@ class BuildList < ActiveRecord::Base
before_transition do |build_list, transition|
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status])
MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id
build_list.counters_logs.create(:status => build_list.status, :event => "decrement", :mass_build_id => build_list.mass_build_id)
end
end
after_transition do |build_list, transition|
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status])
MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id
build_list.counters_logs.create(:status => build_list.status, :event => "increment", :mass_build_id => build_list.mass_build_id)
end
end

View File

@ -0,0 +1,4 @@
class CountersLog < ActiveRecord::Base
belongs_to :build_list
belongs_to :mass_build
end

View File

@ -2,6 +2,7 @@ class MassBuild < ActiveRecord::Base
belongs_to :platform
belongs_to :user
has_many :build_lists, :dependent => :destroy
has_many :counters_logs, :dependent => :destroy
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }

View File

@ -0,0 +1,11 @@
class CreateCountersLogs < ActiveRecord::Migration
def change
create_table :counters_logs do |t|
t.integer :mass_build_id
t.integer :build_list_id
t.string :status
t.string :event
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120719045806) do
ActiveRecord::Schema.define(:version => 20120726110848) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -143,6 +143,15 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
t.integer "project_id"
end
create_table "counters_logs", :force => true do |t|
t.integer "mass_build_id"
t.integer "build_list_id"
t.string "status"
t.string "event"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "event_logs", :force => true do |t|
t.integer "user_id"
t.string "user_name"
@ -160,12 +169,12 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
end
create_table "flash_notifies", :force => true do |t|
t.text "body_ru", :null => false
t.text "body_en", :null => false
t.string "status", :null => false
t.boolean "published", :default => true, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "body_ru"
t.text "body_en"
t.string "status"
t.boolean "published"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "groups", :force => true do |t|
@ -193,6 +202,15 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
create_table "key_pairs", :force => true do |t|
t.integer "repository_id"
t.integer "user_id"
t.integer "key_id"
t.string "public"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "labelings", :force => true do |t|
t.integer "label_id", :null => false
t.integer "issue_id"
@ -311,27 +329,25 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false
t.integer "build_count", :default => 0, :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
create_table "register_requests", :force => true do |t|
t.string "name"
t.string "email"
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "interest"
t.text "more"
end
@ -385,6 +401,7 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
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 "reset_password_token"
t.datetime "remember_created_at"
t.datetime "created_at"
@ -392,8 +409,11 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.datetime "reset_password_sent_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.text "professional_experience"
t.string "site"
t.string "company"
@ -405,9 +425,6 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token"
t.integer "build_priority", :default => 50
end