2011-11-11 17:13:09 +00:00
|
|
|
class ProductBuildList < ActiveRecord::Base
|
2014-03-11 08:58:36 +00:00
|
|
|
include CommitAndVersion
|
|
|
|
include TimeLiving
|
|
|
|
include FileStoreClean
|
|
|
|
include UrlHelper
|
2014-03-11 07:39:25 +00:00
|
|
|
include EventLoggable
|
2015-03-03 22:23:30 +00:00
|
|
|
include ProductBuildLists::Statusable
|
|
|
|
include ProductBuildLists::AbfWorkerable
|
2012-11-06 14:13:16 +00:00
|
|
|
|
2013-03-22 18:18:54 +00:00
|
|
|
LIVE_TIME = 2.week # for autostart
|
|
|
|
MAX_LIVE_TIME = 3.month # for manual start;
|
|
|
|
|
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-12-14 15:14:33 +00:00
|
|
|
belongs_to :user
|
2012-11-06 14:13:16 +00:00
|
|
|
|
2013-03-07 10:24:33 +00:00
|
|
|
# see: Issue #6
|
2014-03-18 13:58:51 +00:00
|
|
|
before_validation -> { self.arch_id = Arch.find_by(name: 'x86_64').id }, on: :create
|
2013-03-27 14:01:54 +00:00
|
|
|
# field "not_delete" can be changed only if build has been completed
|
2014-03-11 07:39:25 +00:00
|
|
|
before_validation -> { self.not_delete = false unless build_completed?; true }
|
2014-12-18 10:07:27 +00:00
|
|
|
|
2014-11-25 17:33:54 +00:00
|
|
|
validates :product, :product_id,
|
|
|
|
:project, :project_id,
|
2012-11-12 13:22:19 +00:00
|
|
|
:main_script,
|
2014-11-25 17:33:54 +00:00
|
|
|
:arch, :arch_id,
|
|
|
|
presence: true
|
2014-01-21 04:51:49 +00:00
|
|
|
validates :main_script, :params, length: { maximum: 255 }
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2014-10-29 22:41:48 +00:00
|
|
|
attr_accessor :base_url, :product_name
|
2015-03-03 21:04:37 +00:00
|
|
|
attr_accessible :base_url,
|
2012-11-13 09:27:39 +00:00
|
|
|
:branch,
|
|
|
|
:project_id,
|
|
|
|
:main_script,
|
|
|
|
:params,
|
|
|
|
:project_version,
|
|
|
|
:commit_hash,
|
2013-03-22 14:06:13 +00:00
|
|
|
:product_id,
|
2014-10-29 22:41:48 +00:00
|
|
|
:not_delete,
|
|
|
|
:product_name
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2014-10-29 22:41:48 +00:00
|
|
|
scope :default_order, -> { order(updated_at: :desc) }
|
|
|
|
scope :for_user, -> (user) { where(user_id: user.id) }
|
|
|
|
scope :scoped_to_product_name, -> (product_name) {
|
|
|
|
joins(:product).where('products.name LIKE ?', "%#{product_name}%") if product_name.present?
|
|
|
|
}
|
|
|
|
scope :recent, -> { order(updated_at: :desc) }
|
2014-03-11 07:39:25 +00:00
|
|
|
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)
|
|
|
|
}
|
2011-11-11 17:13:09 +00:00
|
|
|
|
2014-12-23 21:56:30 +00:00
|
|
|
after_initialize :init_project, if: :new_record?
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
def event_log_message
|
2014-01-21 04:51:49 +00:00
|
|
|
{product: product.name}.inspect
|
2011-11-11 17:13:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2014-12-23 21:56:30 +00:00
|
|
|
def init_project
|
|
|
|
self.project ||= product.try(:project)
|
|
|
|
end
|
|
|
|
|
2011-11-11 17:13:09 +00:00
|
|
|
end
|