diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index f8780af42..3ac113822 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -6,24 +6,26 @@ class Api::V1::JobsController < Api::V1::BaseController before_filter :authenticate_user! def shift - if current_user.system? - queues = params[:worker_queues].split(',') - else - queues = BuildList.queues_for current_user + ActiveRecord::Base.transaction do + build_lists = BuildList.for_status(BuildList::BUILD_PENDING).oldest.order(:create_at) + if current_user.system? + build_list = build_lists.not_owned_external_nodes.first + else + build_list = build_lists.external_nodes(:owned).for_user(current_user).first + build_list ||= build_lists.external_nodes(:everything). + accessible_by(current_ability, :everything).first + end + build_list.touch if build_list end - if queue = queues.find{ |q| job = Resque.redis.lpop "queue:#{q}" } - job = JSON.parse job - render :json => { - :job => { - :worker_queue => queue, - :worker_class => job['class'], - :worker_args => job['args'] - } - }.to_json - else - render :nothing => true + if build_list + job = { + :worker_queue => build_list.worker_queue_with_priority, + :worker_class => build_list.worker_queue_class, + :worker_args => [build_list.abf_worker_args] + } end + render :json => { :job => job }.to_json end def status diff --git a/app/helpers/build_lists_helper.rb b/app/helpers/build_lists_helper.rb index be0182b9f..e58bc204f 100644 --- a/app/helpers/build_lists_helper.rb +++ b/app/helpers/build_lists_helper.rb @@ -35,6 +35,12 @@ module BuildListsHelper end.sort_by { |col| col[0] } end + def external_nodes + BuildList::EXTERNAL_NODES.map do |type| + [I18n.t("layout.build_lists.external_nodes.#{type}"), type] + end + end + def mass_build_options options_from_collection_for_select( MassBuild.recent.limit(15), diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 2232d2f82..91ca63460 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -7,11 +7,12 @@ class BuildList < ActiveRecord::Base belongs_to :project belongs_to :arch - belongs_to :save_to_platform, :class_name => 'Platform' + belongs_to :save_to_platform, :class_name => 'Platform' belongs_to :save_to_repository, :class_name => 'Repository' belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :user - belongs_to :publisher, :class_name => 'User' + belongs_to :builder, :class_name => 'User' + belongs_to :publisher, :class_name => 'User' belongs_to :advisory belongs_to :mass_build, :counter_cache => true has_many :items, :class_name => "BuildList::Item", :dependent => :destroy @@ -21,10 +22,12 @@ class BuildList < ActiveRecord::Base UPDATE_TYPES = %w[bugfix security enhancement recommended newpackage] RELEASE_UPDATE_TYPES = %w[bugfix security] EXTRA_PARAMS = %w[cfg_options build_src_rpm build_rpm] + EXTERNAL_NODES = %w[owned everything] validates :project_id, :project_version, :arch, :include_repos, :build_for_platform_id, :save_to_platform_id, :save_to_repository_id, :presence => true validates_numericality_of :priority, :greater_than_or_equal_to => 0 + validates :external_nodes, :inclusion => {:in => EXTERNAL_NODES}, :allow_blank => true validates :update_type, :inclusion => UPDATE_TYPES, :unless => Proc.new { |b| b.advisory.present? } validates :update_type, :inclusion => {:in => RELEASE_UPDATE_TYPES, :message => I18n.t('flash.build_list.frozen_platform')}, @@ -48,11 +51,12 @@ class BuildList < ActiveRecord::Base before_validation :prepare_extra_repositories, :on => :create before_validation :prepare_extra_build_lists, :on => :create before_validation :prepare_extra_params, :on => :create + before_validation lambda { self.auto_publish = false if external_nodes.present?; true }, :on => :create attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash, :arch_id, :project_id, :save_to_repository_id, :update_type, :save_to_platform_id, :project_version, :auto_create_container, - :extra_repositories, :extra_build_lists, :extra_params + :extra_repositories, :extra_build_lists, :extra_params, :external_nodes LIVE_TIME = 4.week # for unpublished MAX_LIVE_TIME = 3.month # for published @@ -110,6 +114,9 @@ class BuildList < ActiveRecord::Base } scope :for_status, lambda {|status| where(:status => status) if status.present? } scope :for_user, lambda { |user| where(:user_id => user.id) } + scope :not_owned_external_nodes, where("#{table_name}.external_nodes is null OR #{table_name}.external_nodes != ?", :owned) + scope :external_nodes, lambda { |type| where("#{table_name}.external_nodes = ?", type) } + scope :oldest, lambda { where("#{table_name}.updated_at < ?", Time.zone.now - 15.seconds) } scope :for_platform, lambda { |platform| where(:build_for_platform_id => platform) } scope :by_mass_build, lambda { |mass_build| where(:mass_build_id => mass_build) } scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) if arch.present? } @@ -160,7 +167,8 @@ class BuildList < ActiveRecord::Base end end - after_transition :on => :place_build, :do => :add_job_to_abf_worker_queue + after_transition :on => :place_build, :do => :add_job_to_abf_worker_queue, + :if => lambda { |build_list| build_list.external_nodes.present? } after_transition :on => :published, :do => [:set_version_and_tag, :actualize_packages] after_transition :on => :publish, :do => :set_publisher @@ -453,7 +461,7 @@ class BuildList < ActiveRecord::Base end git_project_address = project.git_project_address user - # git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production? + git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production? cmd_params = { 'GIT_PROJECT_ADDRESS' => git_project_address, diff --git a/app/views/projects/build_lists/_new_form.html.haml b/app/views/projects/build_lists/_new_form.html.haml index 2a2f11292..97e44ada4 100644 --- a/app/views/projects/build_lists/_new_form.html.haml +++ b/app/views/projects/build_lists/_new_form.html.haml @@ -49,6 +49,11 @@ = hidden_field_tag field, false, :id => nil = check_box_tag field, true, checked = f.label kind + .both + - selected = params[:build_list].try(:[], :external_nodes) ? {:selected => params[:build_list][:external_nodes]} : {} + = f.select :external_nodes, external_nodes, selected.merge(:include_blank => true) + = f.label :external_nodes + .both %br = hidden_field_tag :from_build_list_id, params[:build_list_id] if params[:build_list_id].present? diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index cffaef622..1cd894726 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -67,6 +67,14 @@ .leftlist= t("activerecord.attributes.build_list.updated_at") .rightlist {{build_list.updated_at_utc}} .both + - if @build_list.external_nodes.present? + .leftlist= t("activerecord.attributes.build_list.external_nodes") + .rightlist= I18n.t("layout.build_lists.external_nodes.#{@build_list.external_nodes}") + .both + .leftlist= t("activerecord.attributes.build_list.builder") + .rightlist{'ng-show' => 'build_list.builder'} + %a{'ng-href' => '{{build_list.builder.path}}' } {{build_list.builder.fullname}} + .both .leftlist= t("activerecord.attributes.build_list.is_circle") .rightlist= t("layout.#{@build_list.is_circle?}_") .both diff --git a/app/views/projects/build_lists/show.json.jbuilder b/app/views/projects/build_lists/show.json.jbuilder index 1c298e4bb..8c56365d3 100644 --- a/app/views/projects/build_lists/show.json.jbuilder +++ b/app/views/projects/build_lists/show.json.jbuilder @@ -26,6 +26,11 @@ json.build_list do json.path user_path(@build_list.publisher) end if @build_list.publisher + json.builder do + json.fullname @build_list.builder.try(:fullname) + json.path user_path(@build_list.builder) + end if @build_list.builder + json.advisory do json.(@build_list.advisory, :description, :advisory_id) json.path advisory_path(@build_list.advisory) diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 6c73c9b5f..938394637 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -30,12 +30,14 @@ en: project_version: Version user: User publisher: Publisher + builder: Builder preferences: Preferences started_at: Build started at duration: Build duration in seconds mass_build_id: Mass build commit_hash: Commit hash logs: Logs + external_nodes: External nodes extra_params: label: Extra params @@ -103,6 +105,10 @@ en: related: Related everything: All + external_nodes: + owned: My + everything: All + build_server_status: header: Build server status workers: '- amount' diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 3ba42e28b..6a4caceaa 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -30,11 +30,13 @@ ru: project_version: Версия user: Пользователь publisher: Публикатор + builder: Сборщик preferences: Настройки duration: Длительность билда в секундах mass_build_id: Массовая сборка commit_hash: Хэш коммита logs: Логи + external_nodes: Дополнительные ноды extra_params: label: Дополнительные параметры @@ -102,6 +104,10 @@ ru: related: Связанные everything: Все + external_nodes: + owned: Мои + everything: Все + build_server_status: header: Статус сборочного сервера workers: '- количество' diff --git a/db/migrate/20131016190149_add_external_nodes_into_build_list.rb b/db/migrate/20131016190149_add_external_nodes_into_build_list.rb new file mode 100644 index 000000000..7d88c3356 --- /dev/null +++ b/db/migrate/20131016190149_add_external_nodes_into_build_list.rb @@ -0,0 +1,5 @@ +class AddExternalNodesIntoBuildList < ActiveRecord::Migration + def change + add_column :build_lists, :external_nodes, :string + end +end diff --git a/db/migrate/20131017171426_add_builder_into_build_list.rb b/db/migrate/20131017171426_add_builder_into_build_list.rb new file mode 100644 index 000000000..4d989bcf5 --- /dev/null +++ b/db/migrate/20131017171426_add_builder_into_build_list.rb @@ -0,0 +1,5 @@ +class AddBuilderIntoBuildList < ActiveRecord::Migration + def change + add_column :build_lists, :builder_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 964f7d9fe..e1f6b2ab7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130920133720) do +ActiveRecord::Schema.define(:version => 20131017171426) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -139,6 +139,8 @@ ActiveRecord::Schema.define(:version => 20130920133720) do t.integer "publisher_id" t.integer "group_id" t.text "extra_params" + t.string "external_nodes" + t.integer "builder_id" end add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"