[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)
if request.post?
@platform.delay.build_all(
mass_build = @platform.mass_builds.new
#@platform.delay.build_all(
mass_build.build_all(
:user => current_user,
:repositories => params[:repositories],
: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 :mass_builds
validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
@ -155,12 +157,13 @@ class Platform < ActiveRecord::Base
end
end
def build_all(opt={})
def build_all(opts={})
# Set options to build all need
repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
auto_publish = opts[:auto_publish] || false
user = opts[:user]
mass_build_id = opts[:mass_build_id]
repositories.each do |rep|
rep.projects.find_in_batches(:batch_size => 2) do |group|
@ -168,9 +171,9 @@ class Platform < ActiveRecord::Base
group.each do |p|
arches.map(&:name).each do |arch|
begin
p.build_for(self, user, arch, auto_publish)
p.build_for(self, user, arch, auto_publish, mass_build_id)
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

View File

@ -55,6 +55,10 @@ class Project < ActiveRecord::Base
include Modules::Models::Owner
def is_rpm
is_package
end
def to_param
name
end
@ -70,7 +74,7 @@ class Project < ActiveRecord::Base
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
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)
# If main does not exist, will connect only project platform repository
# 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)
build_lists.create do |bl|
bl.save_to_platform = platform
bl.build_to_platform = platform
bl.build_for_platform = platform
bl.update_type = 'newpackage'
bl.arch = arch
bl.project_version = "latest_#{platform.name}"
@ -89,6 +93,7 @@ class Project < ActiveRecord::Base
bl.auto_publish = true # already set as db default
bl.include_repos = build_ids
bl.priority = priority
bl.mass_build_id = mass_build_id
end
end

View File

@ -1,52 +1,50 @@
- content_for(:sidebar) do
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => :form, :method => :post } do |f|
.bordered.nopadding
.table
%h3= t("activerecord.attributes.build_list.build_for_platform")
- @platform.repositories.each do |rep|
.righter
.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|
.righter
.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
= check_box_tag :auto_publish, true, params[:auto_publish].present?, :id => 'auto_publish'
.righter
= label_tag :auto_publish
.both
.both
%br
= f.submit t("layout.projects.build_button")
%table{:cellpadding => "0", :cellspacing => "0"}
%tbody
.bordered.nopadding
.table
- ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state|
%tr
%td.first
.lefter
= t("layout.build_lists.statuses.#{state.demodulize.downcase}")
%td= BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count
%tr
%td.first
.righter
= BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count
.both
= 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")
%br
%table.tablesorter.unbordered
%thead
%tr
%th.lpadding16= t('layout.platforms.project')
%th.lpadding16= t('activerecord.platform.project')
%th.lpadding16= t('layout.platforms.arch')
%th.lpadding16= t('layout.platforms.build_task')
%tr

View File

@ -43,6 +43,9 @@ en:
project: Project
arch: Architecture
build_task: Build Task
mass_rebuild: Mass Rebuild
arch: Architecture
build_task: Build Task
flash:
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.
ActiveRecord::Schema.define(:version => 20120512102707) do
ActiveRecord::Schema.define(:version => 20120518105225) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
t.string "kind"
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "advisories", :force => true do |t|
@ -118,6 +118,7 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.datetime "started_at"
t.integer "duration"
t.integer "advisory_id"
t.integer "mass_build_id"
end
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"
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|
t.string "description"
t.string "name", :null => false
@ -222,7 +230,7 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false
t.string "distrib_type"
end
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.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
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 "build_count", :default => 0, :null => false
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|
t.string "name"
t.string "email"
@ -367,16 +373,19 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.string "name"
t.string "email", :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.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.string "role"
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.datetime "reset_password_sent_at"
t.text "professional_experience"
t.string "site"
t.string "company"
@ -388,9 +397,6 @@ ActiveRecord::Schema.define(:version => 20120512102707) do
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token"
t.integer "build_priority", :default => 50
end

View File

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