[refs #442] Add mass build model and new build_all fixes

This commit is contained in:
konstantin.grabar 2012-05-18 19:12:51 +04:00
parent 3e57359c96
commit cd3564bb81
10 changed files with 108 additions and 56 deletions

View File

@ -10,7 +10,9 @@ class Platforms::PlatformsController < Platforms::BaseController
@build_lists = BuildList.for_platform(@platform) @build_lists = BuildList.for_platform(@platform)
if request.post? if request.post?
@platform.delay.build_all( mass_build = @platform.mass_builds.new
#@platform.delay.build_all(
mass_build.build_all(
:user => current_user, :user => current_user,
:repositories => params[:repositories], :repositories => params[:repositories],
:arches => params[:arches], :arches => params[:arches],

15
app/models/mass_build.rb Normal file
View File

@ -0,0 +1,15 @@
class MassBuild < ActiveRecord::Base
belongs_to :platform
before_save :set_name
def build_all(opts={})
platform.build_all opts.merge({:mass_build_id => self.id})
end
protected
def set_name
self.name = "#{created_at.to_date.to_s}-#{platform.name}"
end
end

View File

@ -17,6 +17,8 @@ class Platform < ActiveRecord::Base
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
has_many :mass_builds
validates :description, :presence => true validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
@ -155,12 +157,13 @@ class Platform < ActiveRecord::Base
end end
end end
def build_all(opt={}) def build_all(opts={})
# Set options to build all need # Set options to build all need
repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
auto_publish = opts[:auto_publish] || false auto_publish = opts[:auto_publish] || false
user = opts[:user] user = opts[:user]
mass_build_id = opts[:mass_build_id]
repositories.each do |rep| repositories.each do |rep|
rep.projects.find_in_batches(:batch_size => 2) do |group| rep.projects.find_in_batches(:batch_size => 2) do |group|
@ -168,9 +171,9 @@ class Platform < ActiveRecord::Base
group.each do |p| group.each do |p|
arches.map(&:name).each do |arch| arches.map(&:name).each do |arch|
begin begin
p.build_for(self, user, arch, auto_publish) p.build_for(self, user, arch, auto_publish, mass_build_id)
rescue RuntimeError, Exception rescue RuntimeError, Exception
p.delay.build_for(self, user, arch, auto_publish) p.build_for(self, user, arch, auto_publish, mass_build_id)
end end
end end
end end

View File

@ -55,6 +55,10 @@ class Project < ActiveRecord::Base
include Modules::Models::Owner include Modules::Models::Owner
def is_rpm
is_package
end
def to_param def to_param
name name
end end
@ -70,7 +74,7 @@ class Project < ActiveRecord::Base
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
end end
def build_for(platform, user, arch = 'i586', auto_publish = false, priority = 0) def build_for(platform, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0)
# Select main and project platform repository(contrib, non-free and etc) # Select main and project platform repository(contrib, non-free and etc)
# If main does not exist, will connect only project platform repository # If main does not exist, will connect only project platform repository
# If project platform repository is main, only main will be connect # If project platform repository is main, only main will be connect
@ -80,7 +84,7 @@ class Project < ActiveRecord::Base
arch = Arch.find_by_name(arch) if arch.acts_like?(:string) arch = Arch.find_by_name(arch) if arch.acts_like?(:string)
build_lists.create do |bl| build_lists.create do |bl|
bl.save_to_platform = platform bl.save_to_platform = platform
bl.build_to_platform = platform bl.build_for_platform = platform
bl.update_type = 'newpackage' bl.update_type = 'newpackage'
bl.arch = arch bl.arch = arch
bl.project_version = "latest_#{platform.name}" bl.project_version = "latest_#{platform.name}"
@ -89,6 +93,7 @@ class Project < ActiveRecord::Base
bl.auto_publish = true # already set as db default bl.auto_publish = true # already set as db default
bl.include_repos = build_ids bl.include_repos = build_ids
bl.priority = priority bl.priority = priority
bl.mass_build_id = mass_build_id
end end
end end

View File

@ -1,52 +1,50 @@
- content_for(:sidebar) do - content_for(:sidebar) do
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => :form, :method => :post } do |f| = form_for :build, :url => build_all_platform_path(@platform), :html => { :class => :form, :method => :post } do |f|
.table .bordered.nopadding
%h3= t("activerecord.attributes.build_list.build_for_platform") .table
- @platform.repositories.each do |rep| %h3= t("activerecord.attributes.build_list.build_for_platform")
- @platform.repositories.each do |rep|
.lefter
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}"
.righter
= label_tag "repositories_#{rep.id}", rep.name
.both
.table
%h3= t("activerecord.attributes.build_list.arch")
- Arch.recent.each do |arch|
.lefter
= check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}"
.righter
= label_tag "arches_#{arch.id}", arch.name
.both
.table
%h3= t("activerecord.attributes.build_list.preferences")
.righter .righter
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}" = check_box_tag :auto_publish, true, params[:auto_publish].present?, :id => 'auto_publish'
= label_tag "repositories_#{rep.id}", rep.name
.both
.table
%h3= t("activerecord.attributes.build_list.arch")
- Arch.recent.each do |arch|
.righter .righter
= check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" = label_tag :auto_publish
= label_tag "arches_#{arch.id}", arch.name .both
.both .both
.table %br
%h3= t("activerecord.attributes.build_list.preferences") = f.submit t("layout.projects.build_button")
.righter
= check_box_tag :auto_publish, true, params[:auto_publish].present?, :id => 'auto_publish'
= label_tag :auto_publish
.both
%br
= f.submit t("layout.projects.build_button")
%table{:cellpadding => "0", :cellspacing => "0"} .bordered.nopadding
%tbody .table
- ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state| - ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state|
%tr .lefter
%td.first
= t("layout.build_lists.statuses.#{state.demodulize.downcase}") = t("layout.build_lists.statuses.#{state.demodulize.downcase}")
%td= BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count .righter
%tr = BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count
%td.first .both
= link_to t("layout.activity_feed.all_my_builds"), build_lists_path = link_to t("layout.activity_feed.all_my_builds"), build_lists_path
%td  
.buttons_block
- if can? :build_all, @platform
= link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button left_floated"
-# if can? :cancel_all, @platform
= link_to t("layout.platforms.cancel_all"), cancel_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button left_floated"
%h3.fix= t("layout.platforms.mass_rebuild") %h3.fix= t("layout.platforms.mass_rebuild")
%br
%table.tablesorter.unbordered %table.tablesorter.unbordered
%thead %thead
%tr %tr
%th.lpadding16= t('layout.platforms.project') %th.lpadding16= t('activerecord.platform.project')
%th.lpadding16= t('layout.platforms.arch') %th.lpadding16= t('layout.platforms.arch')
%th.lpadding16= t('layout.platforms.build_task') %th.lpadding16= t('layout.platforms.build_task')
%tr %tr

View File

@ -43,6 +43,9 @@ en:
project: Project project: Project
arch: Architecture arch: Architecture
build_task: Build Task build_task: Build Task
mass_rebuild: Mass Rebuild
arch: Architecture
build_task: Build Task
flash: flash:
platform: platform:

View File

@ -0,0 +1,10 @@
class CreateMassBuilds < ActiveRecord::Migration
def change
create_table :mass_builds do |t|
t.integer :platform_id
t.string :name
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
class AddMassBuildIdToBuildLists < ActiveRecord::Migration
def change
add_column :build_lists, :mass_build_id, :integer
end
end

View File

@ -11,14 +11,14 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120512102707) do ActiveRecord::Schema.define(:version => 20120518105225) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.string "kind" t.string "kind"
t.text "data" t.text "data"
t.datetime "created_at", :null => false t.datetime "created_at"
t.datetime "updated_at", :null => false t.datetime "updated_at"
end end
create_table "advisories", :force => true do |t| create_table "advisories", :force => true do |t|
@ -118,6 +118,7 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.datetime "started_at" t.datetime "started_at"
t.integer "duration" t.integer "duration"
t.integer "advisory_id" t.integer "advisory_id"
t.integer "mass_build_id"
end end
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id" add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"
@ -211,6 +212,13 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
add_index "labels", ["project_id"], :name => "index_labels_on_project_id" add_index "labels", ["project_id"], :name => "index_labels_on_project_id"
create_table "mass_builds", :force => true do |t|
t.integer "platform_id"
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "platforms", :force => true do |t| create_table "platforms", :force => true do |t|
t.string "description" t.string "description"
t.string "name", :null => false t.string "name", :null => false
@ -222,7 +230,7 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.string "owner_type" t.string "owner_type"
t.string "visibility", :default => "open", :null => false t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false t.string "distrib_type"
end end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
@ -293,19 +301,17 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.text "description" t.text "description"
t.string "ancestry" t.string "ancestry"
t.boolean "has_issues", :default => true t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name" t.string "srpm_file_name"
t.string "srpm_content_type" t.string "srpm_content_type"
t.integer "srpm_file_size" t.integer "srpm_file_size"
t.datetime "srpm_updated_at" t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master" t.string "default_branch", :default => "master"
t.boolean "is_rpm", :default => true t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false t.integer "average_build_time", :default => 0, :null => false
t.integer "build_count", :default => 0, :null => false t.integer "build_count", :default => 0, :null => false
end end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
create_table "register_requests", :force => true do |t| create_table "register_requests", :force => true do |t|
t.string "name" t.string "name"
t.string "email" t.string "email"
@ -367,16 +373,19 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.string "name" t.string "name"
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.text "ssh_key"
t.string "uname" t.string "uname"
t.string "role" t.string "role"
t.string "language", :default => "en" t.string "language", :default => "en"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "own_projects_count", :default => 0, :null => false t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.text "professional_experience" t.text "professional_experience"
t.string "site" t.string "site"
t.string "company" t.string "company"
@ -388,9 +397,6 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.integer "failed_attempts", :default => 0 t.integer "failed_attempts", :default => 0
t.string "unlock_token" t.string "unlock_token"
t.datetime "locked_at" t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token" t.string "authentication_token"
t.integer "build_priority", :default => 50 t.integer "build_priority", :default => 50
end end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe MassBuild do
pending "add some examples to (or delete) #{__FILE__}"
end