From 44cbfe619155e55073e7c34613f1ad42b3c7dc14 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 12 May 2014 23:55:13 +0400 Subject: [PATCH] #373: added use_cached_chroot field to MassBuild --- app/models/mass_build.rb | 50 ++++++++++++------- app/models/project.rb | 3 +- .../platforms/mass_builds/index.html.haml | 2 +- app/views/platforms/mass_builds/new.html.haml | 2 +- config/locales/models/mass_build.en.yml | 1 + config/locales/models/mass_build.ru.yml | 1 + ...059_add_use_cached_chroot_to_build_list.rb | 2 +- ...926_add_use_cached_chroot_to_mass_build.rb | 12 +++++ db/schema.rb | 3 +- 9 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20140512183926_add_use_cached_chroot_to_mass_build.rb diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index a8f720f05..da4fccbb0 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -2,36 +2,48 @@ class MassBuild < ActiveRecord::Base belongs_to :build_for_platform, -> { where(platform_type: 'main') }, class_name: 'Platform' belongs_to :save_to_platform, class_name: 'Platform' belongs_to :user - has_many :build_lists, dependent: :destroy + has_many :build_lists, dependent: :destroy serialize :extra_repositories, Array serialize :extra_build_lists, Array - scope :recent, -> { order(created_at: :desc) } - scope :by_platform, ->(platform) { where(save_to_platform_id: platform.id) } - scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) } + scope :recent, -> { order(created_at: :desc) } + scope :by_platform, -> (platform) { where(save_to_platform_id: platform.id) } + scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) } attr_accessor :arches attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id, - :extra_repositories, :extra_build_lists, :increase_release_tag + :extra_repositories, :extra_build_lists, :increase_release_tag, + :use_cached_chroot - validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, presence: true - validates :projects_list, length: {maximum: 500_000}, presence: true - validates_inclusion_of :auto_publish, :increase_release_tag, in: [true, false] + validates :save_to_platform_id, + :build_for_platform_id, + :arch_names, + :name, + :user_id, presence: true + + validates :projects_list, + presence: true, + length: { maximum: 500_000 } + + validates :auto_publish, + :increase_release_tag, + :use_cached_chroot, + inclusion: { in: [true, false] } after_commit :build_all, on: :create before_validation :set_data, on: :create - COUNT_STATUSES = [ - :build_lists, - :build_published, - :build_pending, - :build_started, - :build_publish, - :build_error, - :success, - :build_canceled - ] + COUNT_STATUSES = %i( + build_lists + build_published + build_pending + build_started + build_publish + build_error + success + build_canceled + ) def build_all # later with resque @@ -47,7 +59,7 @@ class MassBuild < ActiveRecord::Base increase_rt = increase_release_tag? arches_list.each do |arch| rep_id = (project.repository_ids & save_to_platform.repository_ids).first - project.build_for self, rep_id, arch, 0, increase_rt + project.build_for(self, rep_id, arch, 0, increase_rt, use_cached_chroot) increase_rt = false end rescue RuntimeError, Exception diff --git a/app/models/project.rb b/app/models/project.rb index 6eb3700f4..8accb89fa 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -166,7 +166,7 @@ class Project < ActiveRecord::Base #path #share by NFS end - def build_for(mass_build, repository_id, arch = Arch.find_by(name: 'i586'), priority = 0, increase_rt = false) + def build_for(mass_build, repository_id, arch = Arch.find_by(name: 'i586'), priority = 0, increase_rt = false, use_cached_chroot = false) build_for_platform = mass_build.build_for_platform save_to_platform = mass_build.save_to_platform user = mass_build.user @@ -194,6 +194,7 @@ class Project < ActiveRecord::Base bl.priority = priority bl.mass_build_id = mass_build.id bl.save_to_repository_id = repository_id + bl.use_cached_chroot = use_cached_chroot end build_list.save end diff --git a/app/views/platforms/mass_builds/index.html.haml b/app/views/platforms/mass_builds/index.html.haml index 63825f1a2..46f62e70b 100644 --- a/app/views/platforms/mass_builds/index.html.haml +++ b/app/views/platforms/mass_builds/index.html.haml @@ -53,7 +53,7 @@ .toggle{id: "toggle_#{ mass_build.id }"} = t('activerecord.attributes.mass_build.user') + ": " = link_to mass_build.user.fullname, mass_build.user - - [:arch_names, :auto_publish, :increase_release_tag, :created_at].each do |field| + - %i(arch_names auto_publish increase_release_tag use_cached_chroot created_at).each do |field| .both = t("activerecord.attributes.mass_build.#{field}") + ": " = mass_build.send field diff --git a/app/views/platforms/mass_builds/new.html.haml b/app/views/platforms/mass_builds/new.html.haml index da9e2a2ab..aea876e77 100644 --- a/app/views/platforms/mass_builds/new.html.haml +++ b/app/views/platforms/mass_builds/new.html.haml @@ -40,7 +40,7 @@ subject: @mass_build, autocomplete_path: autocomplete_extra_build_list_autocompletes_path %h3= t("activerecord.attributes.build_list.preferences") - - [:auto_publish, :increase_release_tag].each do |field| + - %i(auto_publish increase_release_tag use_cached_chroot).each do |field| .both = f.check_box field = f.label field diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index c831c7807..497a038a1 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -27,5 +27,6 @@ en: user: User auto_publish: Automated publishing increase_release_tag: Increase release tag + use_cached_chroot: Use cached chroot repositories: Repositories projects_list: Projects list diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 9cbe40482..62db8514b 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -27,5 +27,6 @@ ru: user: Пользователь auto_publish: Автоматическая публикация increase_release_tag: Увеличить release тег + use_cached_chroot: Использовать кэшированный chroot repositories: Репозитории projects_list: Список проектов diff --git a/db/migrate/20140407181059_add_use_cached_chroot_to_build_list.rb b/db/migrate/20140407181059_add_use_cached_chroot_to_build_list.rb index 8909c5e83..05d0176b1 100644 --- a/db/migrate/20140407181059_add_use_cached_chroot_to_build_list.rb +++ b/db/migrate/20140407181059_add_use_cached_chroot_to_build_list.rb @@ -1,5 +1,5 @@ class AddUseCachedChrootToBuildList < ActiveRecord::Migration - def change + def up # Make existing build_lists 'false', but default to 'true' in the future. add_column :build_lists, :use_cached_chroot, :boolean, null: false, default: false change_column :build_lists, :use_cached_chroot, :boolean, null: false, default: true diff --git a/db/migrate/20140512183926_add_use_cached_chroot_to_mass_build.rb b/db/migrate/20140512183926_add_use_cached_chroot_to_mass_build.rb new file mode 100644 index 000000000..8d21b3ccf --- /dev/null +++ b/db/migrate/20140512183926_add_use_cached_chroot_to_mass_build.rb @@ -0,0 +1,12 @@ +class AddUseCachedChrootToMassBuild < ActiveRecord::Migration + def up + # Make existing mass_builds 'false', but default to 'true' in the future. + add_column :mass_builds, :use_cached_chroot, :boolean, null: false, default: false + change_column :mass_builds, :use_cached_chroot, :boolean, null: false, default: true + end + + def down + remove_column :mass_builds, :use_cached_chroot + end + +end diff --git a/db/schema.rb b/db/schema.rb index 5d07c2dfc..88e153f11 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140512091135) do +ActiveRecord::Schema.define(version: 20140512183926) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -323,6 +323,7 @@ ActiveRecord::Schema.define(version: 20140512091135) do t.text "extra_repositories" t.text "extra_build_lists" t.boolean "increase_release_tag", default: false, null: false + t.boolean "use_cached_chroot", default: true, null: false end create_table "users", force: true do |t|