2012-05-18 16:12:51 +01:00
|
|
|
class MassBuild < ActiveRecord::Base
|
|
|
|
belongs_to :platform
|
2012-05-23 15:08:11 +01:00
|
|
|
belongs_to :user
|
|
|
|
has_many :build_lists, :dependent => :destroy
|
2012-05-18 16:12:51 +01:00
|
|
|
|
2012-05-21 11:18:29 +01:00
|
|
|
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
|
2012-08-06 22:07:54 +01:00
|
|
|
scope :outdated, where('created_at < ?', Time.now + 1.day - BuildList::MAX_LIVE_TIME)
|
2012-05-21 11:18:29 +01:00
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
attr_accessor :repositories, :arches
|
2012-12-06 17:59:17 +00:00
|
|
|
attr_accessible :repositories, :arches, :auto_publish, :projects_list
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-12-06 17:59:17 +00:00
|
|
|
validates :platform_id, :arch_names, :name, :user_id, :presence => true
|
|
|
|
validate :rep_names, :repositories, :presence => true, :if => Proc.new {|mb| mb.projects_list.blank?}
|
2012-05-29 14:44:30 +01:00
|
|
|
validates_inclusion_of :auto_publish, :in => [true, false]
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
after_create :build_all
|
2012-07-09 17:13:02 +01:00
|
|
|
before_validation :set_data
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-06-27 10:48:54 +01:00
|
|
|
COUNT_STATUSES = [
|
|
|
|
:build_lists,
|
|
|
|
:build_published,
|
|
|
|
:build_pending,
|
|
|
|
:build_started,
|
|
|
|
:build_publish,
|
|
|
|
:build_error
|
|
|
|
]
|
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
# ATTENTION: repositories and arches must be set before calling this method!
|
|
|
|
def build_all
|
2012-12-06 17:59:17 +00:00
|
|
|
# later with resque
|
|
|
|
if projects_list.present?
|
|
|
|
platform.build_from_list :mass_build_id => self.id
|
|
|
|
else
|
|
|
|
platform.build_all(
|
|
|
|
:mass_build_id => self.id,
|
|
|
|
:user => self.user,
|
|
|
|
:repositories => self.repositories,
|
|
|
|
:arches => self.arches,
|
|
|
|
:auto_publish => self.auto_publish
|
|
|
|
)
|
|
|
|
end
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|
2012-06-22 16:10:44 +01:00
|
|
|
|
|
|
|
def generate_failed_builds_list
|
|
|
|
report = ""
|
|
|
|
BuildList.where(:status => BuildServer::BUILD_ERROR, :mass_build_id => self.id).each do |build_list|
|
|
|
|
report << "ID: #{build_list.id}; "
|
|
|
|
report << "PROJECT_NAME: #{build_list.project.name}\n"
|
|
|
|
end
|
|
|
|
report
|
|
|
|
end
|
2012-06-28 16:23:33 +01:00
|
|
|
|
|
|
|
def cancel_all
|
2012-09-06 11:53:03 +01:00
|
|
|
update_column(:stop_build, true)
|
2012-08-15 14:52:32 +01:00
|
|
|
build_lists.find_each(:batch_size => 100) do |bl|
|
2012-06-29 17:01:32 +01:00
|
|
|
bl.cancel
|
|
|
|
end
|
2012-06-28 16:23:33 +01:00
|
|
|
end
|
2012-07-02 15:50:47 +01:00
|
|
|
later :cancel_all, :queue => :clone_build
|
2012-07-09 17:13:02 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_data
|
|
|
|
if new_record?
|
|
|
|
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
|
|
|
|
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
|
|
|
|
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|