#759: save sec of time_living instead of minut, some fixes of state_machine

This commit is contained in:
Vokhmin Alexey V 2012-12-07 15:11:12 +04:00
parent f8cbae424e
commit a8e1cea057
9 changed files with 62 additions and 23 deletions

View File

@ -1,5 +1,7 @@
# -*- encoding : utf-8 -*-
class Product < ActiveRecord::Base
include Modules::Models::TimeLiving
belongs_to :platform
belongs_to :project
has_many :product_build_lists, :dependent => :destroy
@ -13,8 +15,7 @@ class Product < ActiveRecord::Base
:description,
:project_id,
:main_script,
:params,
:time_living
:params
attr_readonly :platform_id
def full_clone(attrs = {})

View File

@ -1,6 +1,7 @@
# -*- encoding : utf-8 -*-
class ProductBuildList < ActiveRecord::Base
include Modules::Models::CommitAndVersion
include Modules::Models::TimeLiving
include AbfWorker::ModelHelper
delegate :url_helpers, to: 'Rails.application.routes'
@ -10,15 +11,13 @@ class ProductBuildList < ActiveRecord::Base
BUILD_STARTED = 3
BUILD_CANCELED = 4
BUILD_CANCELING = 5
WAITING_FOR_RESPONSE = 4000
STATUSES = [ BUILD_STARTED,
BUILD_COMPLETED,
BUILD_FAILED,
BUILD_PENDING,
BUILD_CANCELED,
BUILD_CANCELING,
WAITING_FOR_RESPONSE
BUILD_CANCELING
]
HUMAN_STATUSES = { BUILD_STARTED => :build_started,
@ -26,8 +25,7 @@ class ProductBuildList < ActiveRecord::Base
BUILD_FAILED => :build_failed,
BUILD_PENDING => :build_pending,
BUILD_CANCELED => :build_canceled,
BUILD_CANCELING => :build_canceling,
WAITING_FOR_RESPONSE => :waiting_for_response
BUILD_CANCELING => :build_canceling
}
belongs_to :product
@ -39,7 +37,6 @@ class ProductBuildList < ActiveRecord::Base
:status,
:project_id,
:main_script,
:time_living,
:arch_id, :presence => true
validates :status, :inclusion => { :in => STATUSES }
@ -52,7 +49,6 @@ class ProductBuildList < ActiveRecord::Base
:params,
:project_version,
:commit_hash,
:time_living,
:arch_id
attr_readonly :product_id
serialize :results, Array
@ -64,17 +60,11 @@ class ProductBuildList < ActiveRecord::Base
scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")}
scope :recent, order("#{table_name}.updated_at DESC")
after_create :place_build
after_create :add_job_to_abf_worker_queue
before_destroy :can_destroy?
after_destroy :xml_delete_iso_container
state_machine :status, :initial => :waiting_for_response do
event :place_build do
transition :waiting_for_response => :build_pending, :if => lambda { |pbl|
pbl.add_job_to_abf_worker_queue
}
end
state_machine :status, :initial => :build_pending do
event :start_build do
transition :build_pending => :build_started
@ -151,7 +141,7 @@ class ProductBuildList < ActiveRecord::Base
# :srcpath => 'http://dl.dropbox.com/u/945501/avokhmin-test-iso-script-5d9b463d4e9c06ea8e7c89e1b7ff5cb37e99e27f.tar.gz',
:srcpath => srcpath,
:params => params,
:time_living => (time_living * 60),
:time_living => time_living,
:main_script => main_script,
:arch => arch.name,
:distrib_type => product.platform.distrib_type

View File

@ -18,9 +18,11 @@
= render 'show_field', :key => :project_version, :value => product_build_list_version_link(pbl, true)
= render 'show_field', :key => :arch, :value => pbl.arch.name
- [:main_script, :params, :time_living].each do |el|
- [:main_script, :params].each do |el|
= render 'show_field', :key => el, :value => pbl.send(el)
= render 'show_field', :key => :time_living, :value => (pbl.time_living / 60)
= render 'show_field', :key => :notified_at, :value => l(pbl.updated_at, :format => :long)
- if pbl.can_cancel? && can?(:cancel, pbl)

View File

@ -1,4 +1,8 @@
- [:main_script, :params, :time_living].each do |el|
- [:main_script, :params].each do |el|
.leftlist= f.label el, t("activerecord.attributes.product_build_list.#{el}"), :class => :label
.rightlist= f.text_field el
.both
.both
.leftlist= f.label :time_living, t("activerecord.attributes.product_build_list.time_living"), :class => :label
.rightlist= f.text_field :time_living, :value => (@product.time_living / 60)
.both

View File

@ -31,4 +31,5 @@ en:
build_status: Build status
created_at: Created
updated_at: Updated
project: Project
project: Project
time_living: Max time for building (in minutes)

View File

@ -31,4 +31,5 @@ ru:
build_status: Статус последней сборки
created_at: Создан
updated_at: Обновлен
project: Проект
project: Проект
time_living: Максимальное время сборки (в минутах)

View File

@ -0,0 +1,4 @@
en:
flash:
time_living:
numericality_error: must be 2 to 720 minut

View File

@ -0,0 +1,4 @@
ru:
flash:
time_living:
numericality_error: должно быть от 2 до 720 минут

View File

@ -0,0 +1,32 @@
# -*- encoding : utf-8 -*-
module Modules
module Models
module TimeLiving
extend ActiveSupport::Concern
included do
validates :time_living, :numericality => {
:only_integer => true
}, :presence => true
validate lambda {
# 2 min <= time_living <= 12 hours
if 120 > time_living || time_living > 43200
errors.add(:time_living, I18n.t('flash.time_living.numericality_error'))
end
}
before_validation :convert_time_living
attr_accessible :time_living
end
protected
def convert_time_living
self.time_living = time_living.to_i * 60 if time_living_was.to_i != time_living.to_i
end
end
end
end