#405: Run mass builds with relations

This commit is contained in:
Vokhmin Alexey V 2014-07-10 00:24:41 +04:00
parent 21d705610b
commit c263df2fec
6 changed files with 86 additions and 4 deletions

View File

@ -0,0 +1,31 @@
class RunExtraMassBuildsJob
@queue = :low
def self.perform
RunExtraMassBuildsJob.new.perform
end
def perform
MassBuild.where(status: BUILD_PENDING).find_each do |mb|
next if mb.extra_mass_builds.blank?
next if mb.extra_mass_builds.exclude?(mass_build_id)
emb = MassBuild.where(status: SUCCESS, id: mb.extra_mass_builds).to_a
next if emb.size != mb.extra_mass_builds.size
next if emb.find{ |mb| not_ready?(mb) }
mb.build_all
end
end
private
# Returns true if mass build has not published packages or packages without container
def not_ready?(mb)
mb.build_lists.count != mb.build_lists.where(
'status = ? OR container_status = ?',
BuildList::BUILD_PUBLISHED,
BuildList::BUILD_PUBLISHED
).count
end
end

View File

@ -15,7 +15,7 @@ class BuildList < ActiveRecord::Base
belongs_to :builder, class_name: 'User'
belongs_to :publisher, class_name: 'User'
belongs_to :advisory
belongs_to :mass_build, counter_cache: true, touch: true
belongs_to :mass_build, counter_cache: true
has_many :items, class_name: '::BuildList::Item', dependent: :destroy
has_many :packages, class_name: '::BuildList::Package', dependent: :destroy
has_many :source_packages, -> { where(package_type: 'source') }, class_name: '::BuildList::Package'
@ -172,7 +172,7 @@ class BuildList < ActiveRecord::Base
end
after_transition on: :published,
do: [:set_version_and_tag, :actualize_packages]
do: %i(set_version_and_tag actualize_packages)
after_transition on: :publish, do: :set_publisher
after_transition(on: :publish) do |build_list, transition|
if transition.from == BUILD_PUBLISHED_INTO_TESTING

View File

@ -2,6 +2,34 @@ class MassBuild < ActiveRecord::Base
AUTO_PUBLISH_STATUSES = %w(none default testing)
STATUSES, HUMAN_STATUSES = [], {}
[
%w(SUCCESS 0),
%w(BUILD_STARTED 3000),
%w(BUILD_PENDING 2000),
].each do |kind, value|
value = value.to_i
const_set kind, value
STATUSES << value
HUMAN_STATUSES[value] = kind.downcase.to_sym
end
STATUSES.freeze
HUMAN_STATUSES.freeze
state_machine :status, initial: :build_pending do
event :start do
transition build_pending: :build_started
end
event :done do
transition build_started: :success
end
HUMAN_STATUSES.each do |code,name|
state name, value: code
end
end
belongs_to :build_for_platform, -> { where(platform_type: 'main') }, class_name: 'Platform'
belongs_to :save_to_platform, class_name: 'Platform'
belongs_to :user
@ -43,7 +71,7 @@ class MassBuild < ActiveRecord::Base
:use_extra_tests,
inclusion: { in: [true, false] }
after_commit :build_all, on: :create
after_commit :build_all, on: :create, if: Proc.new { |mb| mb.extra_mass_builds.blank? }
before_validation :set_data, on: :create
COUNT_STATUSES = %i(
@ -58,6 +86,7 @@ class MassBuild < ActiveRecord::Base
)
def build_all
start
# later with resque
arches_list = arch_names ? Arch.where(name: arch_names.split(', ')) : Arch.all
@ -82,6 +111,7 @@ class MassBuild < ActiveRecord::Base
update_column :missed_projects_list, list
end
end
done
end
later :build_all, queue: :low

View File

@ -26,6 +26,13 @@ clean_api_defender_statistics:
queue: low
description: 'Cleans ApiDefender statistics'
run_extra_mass_builds:
every:
- '5m'
class: 'RunExtraMassBuildsJob'
queue: low
description: 'Run mass builds with relations'
restart_nodes:
every:
- '5m'

View File

@ -0,0 +1,13 @@
class AddStatusToMassBuilds < ActiveRecord::Migration
def up
# Sets SUCCESS for all current builds
add_column :mass_builds, :status, :integer, null: false, default: 0 # SUCCESS
# Sets BUILD_PENDING for all new builds
change_column :mass_builds, :status, :integer, null: false, default: 2000 # BUILD_PENDING
end
def down
remove_column :mass_builds, :status
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140701172739) do
ActiveRecord::Schema.define(version: 20140709194335) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -331,6 +331,7 @@ ActiveRecord::Schema.define(version: 20140701172739) do
t.text "extra_mass_builds"
t.boolean "include_testing_subrepository", default: false, null: false
t.boolean "auto_create_container", default: false, null: false
t.integer "status", default: 2000, null: false
end
create_table "users", force: true do |t|