2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-11-11 17:13:09 +00:00
|
|
|
class ProductBuildList < ActiveRecord::Base
|
2012-11-06 14:13:16 +00:00
|
|
|
include Modules::Models::CommitAndVersion
|
2012-12-06 14:41:24 +00:00
|
|
|
include AbfWorker::ModelHelper
|
2012-11-07 14:32:46 +00:00
|
|
|
delegate :url_helpers, to: 'Rails.application.routes'
|
2012-11-06 14:13:16 +00:00
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
BUILD_COMPLETED = 0
|
2012-11-19 15:11:07 +00:00
|
|
|
BUILD_FAILED = 1
|
2012-11-19 16:38:08 +00:00
|
|
|
BUILD_PENDING = 2
|
2012-11-19 15:11:07 +00:00
|
|
|
BUILD_STARTED = 3
|
|
|
|
BUILD_CANCELED = 4
|
2012-11-19 15:41:59 +00:00
|
|
|
BUILD_CANCELING = 5
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2012-03-30 12:26:28 +01:00
|
|
|
STATUSES = [ BUILD_STARTED,
|
|
|
|
BUILD_COMPLETED,
|
2012-11-19 15:11:07 +00:00
|
|
|
BUILD_FAILED,
|
2012-11-19 16:38:08 +00:00
|
|
|
BUILD_PENDING,
|
2012-11-19 15:41:59 +00:00
|
|
|
BUILD_CANCELED,
|
|
|
|
BUILD_CANCELING
|
2012-03-30 12:26:28 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
HUMAN_STATUSES = { BUILD_STARTED => :build_started,
|
|
|
|
BUILD_COMPLETED => :build_completed,
|
2012-11-19 15:11:07 +00:00
|
|
|
BUILD_FAILED => :build_failed,
|
2012-11-19 16:38:08 +00:00
|
|
|
BUILD_PENDING => :build_pending,
|
2012-11-19 15:41:59 +00:00
|
|
|
BUILD_CANCELED => :build_canceled,
|
2012-11-19 16:39:57 +00:00
|
|
|
BUILD_CANCELING => :build_canceling
|
2012-03-30 12:26:28 +01:00
|
|
|
}
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
belongs_to :product
|
2012-11-06 14:13:16 +00:00
|
|
|
belongs_to :project
|
2012-11-13 14:01:06 +00:00
|
|
|
belongs_to :arch
|
2012-11-06 14:13:16 +00:00
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2012-11-12 13:22:19 +00:00
|
|
|
validates :product_id,
|
|
|
|
:status,
|
|
|
|
:project_id,
|
|
|
|
:main_script,
|
2012-11-13 14:01:06 +00:00
|
|
|
:time_living,
|
|
|
|
:arch_id, :presence => true
|
2012-11-19 15:11:07 +00:00
|
|
|
validates :status, :inclusion => { :in => STATUSES }
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2012-04-03 21:32:57 +01:00
|
|
|
attr_accessor :base_url
|
2012-11-13 09:27:39 +00:00
|
|
|
attr_accessible :status,
|
|
|
|
:base_url,
|
|
|
|
:branch,
|
|
|
|
:project_id,
|
|
|
|
:main_script,
|
|
|
|
:params,
|
|
|
|
:project_version,
|
|
|
|
:commit_hash,
|
2012-11-13 14:01:06 +00:00
|
|
|
:time_living,
|
|
|
|
:arch_id
|
2012-04-03 21:32:57 +01:00
|
|
|
attr_readonly :product_id
|
2012-11-08 21:39:42 +00:00
|
|
|
serialize :results, Array
|
2012-04-03 21:32:57 +01:00
|
|
|
|
|
|
|
|
2012-06-28 18:40:32 +01:00
|
|
|
scope :default_order, order('updated_at DESC')
|
2012-03-30 12:26:28 +01:00
|
|
|
scope :for_status, lambda {|status| where(:status => status) }
|
|
|
|
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")
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2012-12-06 17:10:23 +00:00
|
|
|
after_create :add_job_to_abf_worker_queue
|
2012-08-06 13:06:42 +01:00
|
|
|
before_destroy :can_destroy?
|
2012-02-29 11:15:49 +00:00
|
|
|
after_destroy :xml_delete_iso_container
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2012-11-09 17:42:25 +00:00
|
|
|
def build_started?
|
|
|
|
status == BUILD_STARTED
|
|
|
|
end
|
|
|
|
|
2012-11-19 15:41:59 +00:00
|
|
|
def build_canceling?
|
|
|
|
status == BUILD_CANCELING
|
|
|
|
end
|
|
|
|
|
2012-12-06 14:41:24 +00:00
|
|
|
def can_cancel?
|
|
|
|
[BUILD_STARTED, BUILD_PENDING].include? status
|
|
|
|
end
|
|
|
|
|
2012-02-27 16:21:56 +00:00
|
|
|
def container_path
|
|
|
|
"/downloads/#{product.platform.name}/product/#{id}/"
|
|
|
|
end
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
def event_log_message
|
2011-11-11 19:11:27 +00:00
|
|
|
{:product => product.name}.inspect
|
2011-11-11 17:13:09 +00:00
|
|
|
end
|
|
|
|
|
2012-03-30 12:26:28 +01:00
|
|
|
def self.human_status(status)
|
|
|
|
I18n.t("layout.product_build_lists.statuses.#{HUMAN_STATUSES[status]}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def human_status
|
|
|
|
self.class.human_status(status)
|
|
|
|
end
|
|
|
|
|
2012-08-06 13:06:42 +01:00
|
|
|
def can_destroy?
|
2012-11-19 16:38:08 +00:00
|
|
|
[BUILD_COMPLETED, BUILD_FAILED, BUILD_CANCELED].include? status
|
2012-08-06 13:06:42 +01:00
|
|
|
end
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
protected
|
|
|
|
|
2012-12-06 14:41:24 +00:00
|
|
|
def abf_worker_args
|
2012-11-07 14:32:46 +00:00
|
|
|
file_name = "#{project.owner.uname}-#{project.name}-#{commit_hash}"
|
2012-11-08 13:04:02 +00:00
|
|
|
srcpath = url_helpers.archive_url(
|
|
|
|
project.owner,
|
|
|
|
project.name,
|
|
|
|
file_name,
|
|
|
|
'tar.gz',
|
|
|
|
:host => ActionMailer::Base.default_url_options[:host]
|
|
|
|
)
|
2012-12-06 14:41:24 +00:00
|
|
|
{
|
2012-11-07 14:32:46 +00:00
|
|
|
:id => id,
|
2012-11-12 09:41:41 +00:00
|
|
|
# TODO: remove comment
|
2012-11-19 15:48:14 +00:00
|
|
|
# :srcpath => 'http://dl.dropbox.com/u/945501/avokhmin-test-iso-script-5d9b463d4e9c06ea8e7c89e1b7ff5cb37e99e27f.tar.gz',
|
|
|
|
:srcpath => srcpath,
|
2012-11-07 14:32:46 +00:00
|
|
|
:params => params,
|
2012-11-12 13:22:19 +00:00
|
|
|
:time_living => time_living,
|
2012-11-13 14:01:06 +00:00
|
|
|
:main_script => main_script,
|
|
|
|
:arch => arch.name,
|
|
|
|
:distrib_type => product.platform.distrib_type
|
2012-11-07 14:32:46 +00:00
|
|
|
}
|
2012-12-06 14:41:24 +00:00
|
|
|
end
|
2012-03-31 00:37:54 +01:00
|
|
|
|
2012-02-29 11:15:49 +00:00
|
|
|
def xml_delete_iso_container
|
2012-11-07 12:14:31 +00:00
|
|
|
# TODO: write new worker for delete
|
2012-11-09 13:08:56 +00:00
|
|
|
if project
|
|
|
|
raise "Failed to destroy product_build_list #{id} inside platform #{product.platform.name} (Not Implemented)."
|
2012-02-29 11:15:49 +00:00
|
|
|
else
|
2012-11-09 13:08:56 +00:00
|
|
|
result = ProductBuilder.delete_iso_container self
|
|
|
|
if result == ProductBuilder::SUCCESS
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
raise "Failed to destroy product_build_list #{id} inside platform #{product.platform.name} with code #{result}."
|
|
|
|
end
|
2011-11-11 17:13:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|