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
|
|
|
|
2013-05-17 12:42:01 +01:00
|
|
|
scope :recent, order("#{table_name}.created_at DESC")
|
2012-05-21 11:18:29 +01:00
|
|
|
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
|
2013-02-28 15:27:50 +00:00
|
|
|
scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME)
|
2012-05-21 11:18:29 +01:00
|
|
|
|
2012-12-10 19:35:56 +00:00
|
|
|
attr_accessor :arches
|
2013-01-28 21:16:29 +00:00
|
|
|
attr_accessible :arches, :auto_publish, :projects_list
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-12-10 19:35:56 +00:00
|
|
|
validates :platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true
|
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,
|
2013-01-29 15:20:28 +00:00
|
|
|
:build_error,
|
|
|
|
:success,
|
|
|
|
:build_canceled
|
2012-06-27 10:48:54 +01:00
|
|
|
]
|
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
def build_all
|
2012-12-06 17:59:17 +00:00
|
|
|
# later with resque
|
2013-03-11 11:19:13 +00:00
|
|
|
arches_list = arch_names ? Arch.where(:name => arch_names.split(', ')) : Arch.all
|
2012-12-10 19:35:56 +00:00
|
|
|
auto_publish ||= false
|
|
|
|
|
|
|
|
projects_list.lines.each do |name|
|
|
|
|
next if name.blank?
|
|
|
|
name.chomp!; name.strip!
|
|
|
|
|
2012-12-11 13:48:16 +00:00
|
|
|
if project = Project.joins(:repositories).where('repositories.id in (?)', platform.repository_ids).find_by_name(name)
|
2012-12-10 19:35:56 +00:00
|
|
|
begin
|
|
|
|
return if self.reload.stop_build
|
|
|
|
arches_list.each do |arch|
|
|
|
|
rep = (project.repositories & platform.repositories).first
|
2013-01-28 21:16:29 +00:00
|
|
|
project.build_for(platform, rep.id, user, arch, auto_publish, self.id, 0)
|
2012-12-10 19:35:56 +00:00
|
|
|
end
|
|
|
|
rescue RuntimeError, Exception
|
|
|
|
end
|
|
|
|
else
|
|
|
|
MassBuild.increment_counter :missed_projects_count, id
|
|
|
|
list = (missed_projects_list || '') << "#{name}\n"
|
|
|
|
update_column :missed_projects_list, list
|
|
|
|
end
|
2012-12-06 17:59:17 +00:00
|
|
|
end
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|
2012-12-25 16:01:44 +00:00
|
|
|
later :build_all, :queue => :clone_build
|
2012-06-22 16:10:44 +01:00
|
|
|
|
|
|
|
def generate_failed_builds_list
|
|
|
|
report = ""
|
2013-03-27 10:38:52 +00:00
|
|
|
BuildList.select('build_lists.id, projects.name as project_name, arches.name as arch_name').
|
|
|
|
where(
|
2013-03-27 09:59:31 +00:00
|
|
|
:status => BuildList::BUILD_ERROR,
|
|
|
|
:mass_build_id => self.id
|
2013-03-27 10:38:52 +00:00
|
|
|
).joins(:project, :arch).find_in_batches(:batch_size => 100) do |build_lists|
|
2013-03-27 09:59:31 +00:00
|
|
|
build_lists.each do |build_list|
|
|
|
|
report << "ID: #{build_list.id}; "
|
2013-03-27 10:38:52 +00:00
|
|
|
report << "PROJECT_NAME: #{build_list.project_name}; "
|
|
|
|
report << "ARCH: #{build_list.arch_name}\n"
|
2013-03-27 09:59:31 +00:00
|
|
|
end
|
2012-06-22 16:10:44 +01:00
|
|
|
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
|
|
|
|
2013-04-02 14:54:18 +01:00
|
|
|
def publish_success_builds(user)
|
|
|
|
publish user, BuildList::SUCCESS, BuildList::FAILED_PUBLISH
|
2013-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
later :publish_success_builds, :queue => :clone_build
|
|
|
|
|
2013-04-02 14:54:18 +01:00
|
|
|
def publish_test_faild_builds(user)
|
|
|
|
publish user, BuildList::TESTS_FAILED
|
2013-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
later :publish_test_faild_builds, :queue => :clone_build
|
|
|
|
|
2012-07-09 17:13:02 +01:00
|
|
|
private
|
|
|
|
|
2013-04-02 14:54:18 +01:00
|
|
|
def publish(user, *statuses)
|
|
|
|
builds = build_lists.where(:status => statuses)
|
|
|
|
builds.update_all(:publisher_id => user.id)
|
|
|
|
builds.order(:id).find_in_batches(:batch_size => 50) do |bls|
|
2013-03-21 14:41:45 +00:00
|
|
|
bls.each{ |bl| bl.can_publish? && bl.now_publish }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-09 17:13:02 +01:00
|
|
|
def set_data
|
|
|
|
if new_record?
|
|
|
|
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
|