rosa-build/app/models/mass_build.rb

63 lines
1.8 KiB
Ruby
Raw Normal View History

class MassBuild < ActiveRecord::Base
belongs_to :platform
belongs_to :user
has_many :build_lists, :dependent => :destroy
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
2012-05-25 18:31:57 +01:00
attr_accessor :repositories, :arches
attr_accessible :platform, :platform_id, :user, :user_id, :repositories, :arches, :auto_publish
validates :platform_id, :arch_names, :name, :user_id, :repositories, :rep_names, :presence => true
validates_inclusion_of :auto_publish, :in => [true, false]
2012-05-25 18:31:57 +01:00
after_create :build_all
COUNT_STATUSES = [
:build_lists,
:build_published,
:build_pending,
:build_started,
:build_publish,
:build_error
]
2012-05-25 18:31:57 +01:00
def initialize(args = nil)
super
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}"
2012-05-25 18:31:57 +01:00
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
end
end
2012-05-25 18:31:57 +01:00
# ATTENTION: repositories and arches must be set before calling this method!
def build_all
platform.build_all(
2012-05-25 18:31:57 +01:00
:mass_build_id => self.id,
:user => self.user,
:repositories => self.repositories,
:arches => self.arches,
:auto_publish => self.auto_publish
) # later with resque
end
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
def cancel_all
2012-06-29 16:17:25 +01:00
self.update_attribute(:stop_build, true)
self.build_lists.find_each(:batch_size => 100) do |bl|
2012-06-29 17:01:32 +01:00
bl.cancel
end
end
later :cancel_all, :queue => :clone_build
end