From ab8c4016b5786dc6567c36355af978534677bf84 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 6 Dec 2012 21:34:09 +0400 Subject: [PATCH] #759: refactoring according to Vladimir's comments --- app/controllers/projects/build_lists_controller.rb | 13 +++++-------- app/models/build_list.rb | 11 +++++++++++ lib/abf_worker/rpm_worker_observer.rb | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index c9d6a75d7..07bd95353 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -100,15 +100,12 @@ class Projects::BuildListsController < Projects::BaseController end def cancel - if @build_list.new_core? && @build_list.can_cancel? - @build_list.cancel_job - notice = t('layout.build_lists.will_be_canceled') + if @build_list.cancel + notice = @build_list.new_core? ? + t('layout.build_lists.will_be_canceled') : + t('layout.build_lists.cancel_success') else - if @build_list.cancel - notice = t('layout.build_lists.cancel_success') - else - notice = t('layout.build_lists.cancel_fail') - end + notice = t('layout.build_lists.cancel_fail') end redirect_to :back, :notice => notice end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index d2acc0ae9..2050781c4 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -141,6 +141,8 @@ class BuildList < ActiveRecord::Base end after_transition :on => :published, :do => [:set_version_and_tag, :actualize_packages] + after_transition :on => :cancel, :do => [:cancel_job], + :if => lambda { |build_list| build_list.build_canceling? } after_transition :on => [:published, :fail_publish, :build_error], :do => :notify_users after_transition :on => :build_success, :do => :notify_users, @@ -175,6 +177,15 @@ class BuildList < ActiveRecord::Base transition [:build_pending, :platform_pending] => :build_canceled, :if => lambda { |build_list| !build_list.new_core? && build_list.can_cancel? && BuildServer.delete_build_list(build_list.bs_id) == BuildServer::SUCCESS } + transition [:build_pending, :build_started] => :build_canceling, :if => lambda { |build_list| + build_list.new_core? && build_list.can_cancel? + } + end + + event :build_canceled do + transition [:build_canceling] => :build_canceled, :if => lambda { |build_list| + build_list.new_core? + } end event :published do diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index 618114462..212f043ce 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -24,7 +24,7 @@ module AbfWorker bl.save! bl.start_build when BUILD_CANCELED - bl.update_attributes({:status => BuildList::BUILD_CANCELED}) + bl.build_canceled item.update_attributes({:status => BuildList::BUILD_CANCELED}) end if status != BUILD_STARTED