#354: added autostart_status into Project

This commit is contained in:
Vokhmin Alexey V 2014-02-17 00:51:41 +04:00
parent cded4aaba3
commit 5bebb4d5a8
9 changed files with 110 additions and 35 deletions

View File

@ -1,26 +1,14 @@
class Product < ActiveRecord::Base
include Modules::Models::TimeLiving
include Modules::Models::Autostart
belongs_to :platform
belongs_to :project
has_many :product_build_lists, dependent: :destroy
ONCE_A_12_HOURS = 0
ONCE_A_DAY = 1
ONCE_A_WEEK = 2
AUTOSTART_STATUSES = [ONCE_A_12_HOURS, ONCE_A_DAY, ONCE_A_WEEK]
HUMAN_AUTOSTART_STATUSES = {
ONCE_A_12_HOURS => :once_a_12_hours,
ONCE_A_DAY => :once_a_day,
ONCE_A_WEEK => :once_a_week
}
validates :name, presence: true, uniqueness: {scope: :platform_id}
validates :project_id, presence: true
validates :main_script, :params, length: { maximum: 255 }
validates :autostart_status, numericality: true,
inclusion: {in: AUTOSTART_STATUSES}, allow_blank: true
scope :recent, order("#{table_name}.name ASC")
@ -30,7 +18,6 @@ class Product < ActiveRecord::Base
:main_script,
:params,
:platform_id,
:autostart_status,
:project_version
attr_readonly :platform_id
@ -44,16 +31,8 @@ class Product < ActiveRecord::Base
end
end
def human_autostart_status
self.class.human_autostart_status(autostart_status)
end
def self.human_autostart_status(autostart_status)
I18n.t("layout.products.autostart_statuses.#{HUMAN_AUTOSTART_STATUSES[autostart_status]}")
end
class << self
HUMAN_AUTOSTART_STATUSES.each do |autostart_status, human_autostart_status|
Modules::Models::Autostart::HUMAN_AUTOSTART_STATUSES.each do |autostart_status, human_autostart_status|
define_method "autostart_iso_builds_#{human_autostart_status}" do
autostart_iso_builds autostart_status
end

View File

@ -1,4 +1,6 @@
class Project < ActiveRecord::Base
include Modules::Models::Autostart
VISIBILITIES = ['open', 'hidden']
MAX_OWN_PROJECTS = 32000
NAME_REGEXP = /[\w\-\+\.]+/
@ -50,6 +52,8 @@ class Project < ActiveRecord::Base
:url, :srpms_list, :mass_import, :add_to_repository_id, :architecture_dependent
attr_readonly :owner_id, :owner_type
serialize :default_platforms, Array
scope :recent, order("lower(#{table_name}.name) ASC")
scope :search_order, order("CHAR_LENGTH(#{table_name}.name) ASC")
scope :search, lambda {|q|
@ -171,13 +175,7 @@ class Project < ActiveRecord::Base
main_rep_id = build_for_platform.repositories.find_by_name(%w(main base)).try(:id)
include_repos = ([main_rep_id] << (save_to_platform.main? ? repository_id : nil)).compact.uniq
project_version = if repo.commits("#{save_to_platform.name}").try(:first).try(:id)
save_to_platform.name
elsif repo.commits("#{build_for_platform.name}").try(:first).try(:id)
build_for_platform.name
else
default_branch
end
project_version = project_version_for save_to_platform, build_for_platform
increase_release_tag(project_version, user, "MassBuild##{mass_build.id}: Increase release tag") if increase_rt
@ -199,6 +197,16 @@ class Project < ActiveRecord::Base
build_list.save
end
def project_version_for(save_to_platform, build_for_platform)
if repo.commits("#{save_to_platform.name}").try(:first).try(:id)
save_to_platform.name
elsif repo.commits("#{build_for_platform.name}").try(:first).try(:id)
build_for_platform.name
else
default_branch
end
end
def fork(new_owner, new_name = name)
new_name = new_name.presence || name
dup.tap do |c|
@ -290,6 +298,34 @@ class Project < ActiveRecord::Base
end
end
class << self
Modules::Models::Autostart::HUMAN_AUTOSTART_STATUSES.each do |autostart_status, human_autostart_status|
define_method "autostart_build_lists_#{human_autostart_status}" do
autostart_iso_builds autostart_status
end
end
end
def self.autostart_build_lists(autostart_status)
Project.where(autostart_status: autostart_status).find_each do |p|
Platform.where(id: p.default_platforms).each do |platform|
platform.platform_arch_settings.pluck(:arch_id).each do |arch_id|
build_list = build_lists.build do |bl|
bl.save_to_platform = platform
bl.build_for_platform = platform
bl.update_type = 'newpackage'
bl.arch_id = arch_id
bl.project_version = project_version_for(platform, platform)
bl.user = p.owner.is_a?(Group) ? p.owner.owner : p.owner
bl.auto_publish = true # TODO: ???
bl.save_to_repository_id = p.repositories.where(platform_id: platform).first
end
build_list.save
end
end
end
end
protected
def increase_release_tag(project_version, user, message)

View File

@ -55,6 +55,17 @@
autocomplete_maintainers_path(@project.owner, @project),
id_element: '#project_maintainer_id',
placeholder: @project.maintainer.fullname
%h3= t("layout.projects.build_schedule")
= form_for @project, html: { class: :form, multipart: true } do |f|
.leftlist= f.label :default_platforms
.rightlist= f.select :default_platforms, Platform.main.map{ |p| [p.name, p.id] }, {include_blank: true}, multiple: true, size: 5
.both
.leftlist= f.label :autostart_status
.rightlist= f.select :autostart_status, Project::AUTOSTART_STATUSES.collect{|status| [Project.human_autostart_status(status), status]}, {include_blank: true, selected: @project.autostart_status}
.both
- if [:new, :create].include? act
.leftlist= f.label :srpm
.rightlist= f.file_field :srpm, class: 'file_field'

View File

@ -1,6 +1,7 @@
en:
layout:
projects:
build_schedule: Build schedule
mass_import: Mass import
branches: Branches
delete_branch: Delete branch

View File

@ -1,6 +1,7 @@
ru:
layout:
projects:
build_schedule: Расписание сборок
mass_import: Массовый импорт
branches: Ветки
delete_branch: Удалить ветку

View File

@ -41,14 +41,18 @@ end
every :day, at: '4am' do
runner 'Product.autostart_iso_builds_once_a_12_hours', output: 'log/autostart_iso_builds.log'
runner 'Product.autostart_iso_builds_once_a_day', output: 'log/autostart_iso_builds.log'
runner 'BuildList.autostart_build_lists_once_a_12_hours', output: 'log/autostart_build_lists.log'
runner 'BuildList.autostart_build_lists_once_a_day', output: 'log/autostart_build_lists.log'
end
every :day, at: '4pm' do
runner 'Product.autostart_iso_builds_once_a_12_hours', output: 'log/autostart_iso_builds.log'
runner 'BuildList.autostart_build_lists_once_a_12_hours', output: 'log/autostart_build_lists.log'
end
every :sunday, at: '4am' do
runner 'Product.autostart_iso_builds_once_a_week', output: 'log/autostart_iso_builds.log'
runner 'BuildList.autostart_build_lists_once_a_week', output: 'log/autostart_build_lists.log'
end
every :day, at: '1am' do

View File

@ -0,0 +1,6 @@
class AddAutostartStatusToProjects < ActiveRecord::Migration
def change
add_column :projects, :autostart_status, :integer
add_column :projects, :default_platforms, :text
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140211175858) do
ActiveRecord::Schema.define(:version => 20140216203553) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -441,6 +441,8 @@ ActiveRecord::Schema.define(:version => 20140211175858) do
t.boolean "publish_i686_into_x86_64", :default => false
t.string "owner_uname", :null => false
t.boolean "architecture_dependent", :default => false, :null => false
t.integer "autostart_status"
t.text "default_platforms"
end
add_index "projects", ["owner_id", "name", "owner_type"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false

View File

@ -0,0 +1,35 @@
module Modules
module Models
module Autostart
extend ActiveSupport::Concern
ONCE_A_12_HOURS = 0
ONCE_A_DAY = 1
ONCE_A_WEEK = 2
AUTOSTART_STATUSES = [ONCE_A_12_HOURS, ONCE_A_DAY, ONCE_A_WEEK]
HUMAN_AUTOSTART_STATUSES = {
ONCE_A_12_HOURS => :once_a_12_hours,
ONCE_A_DAY => :once_a_day,
ONCE_A_WEEK => :once_a_week
}
included do
validates :autostart_status, numericality: true,
inclusion: {in: AUTOSTART_STATUSES}, allow_blank: true
attr_accessible :autostart_status
end
def human_autostart_status
self.class.human_autostart_status(autostart_status)
end
module ClassMethods
def human_autostart_status(autostart_status)
I18n.t("layout.products.autostart_statuses.#{HUMAN_AUTOSTART_STATUSES[autostart_status]}")
end
end
end
end
end