2011-11-11 17:13:09 +00:00
|
|
|
class ProductBuildList < ActiveRecord::Base
|
2014-03-11 08:58:36 +00:00
|
|
|
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
|
2016-04-29 15:10:30 +01:00
|
|
|
include EventLoggable
|
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-12-14 15:14:33 +00:00
|
|
|
belongs_to :user
|
2012-11-06 14:13:16 +00:00
|
|
|
|
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
|
|
|
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
|
|
|
|
|
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
|