From f7e6dcb88bb82eec3c9d782637da1183a2ad7eb5 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 5 Feb 2014 02:43:01 +0400 Subject: [PATCH 01/34] create separate queues for each mass_build && user --- app/controllers/api/v1/jobs_controller.rb | 55 ++++++++-------- app/models/build_list.rb | 23 +++++++ .../build_lists_publish_task_manager.rb | 8 +-- lib/abf_worker/model_helper.rb | 62 ++++++++++++++++--- 4 files changed, 108 insertions(+), 40 deletions(-) diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index f3a9ef152..45919b4c0 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -7,41 +7,42 @@ class Api::V1::JobsController < Api::V1::BaseController before_filter :authenticate_user! def shift - platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present? - arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present? - build_lists = BuildList.for_status(BuildList::BUILD_PENDING).scoped_to_arch(arch_ids). - oldest.order(:created_at) - build_lists = build_lists.for_platform(platform_ids) if platform_ids.present? if current_user.system? - if task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker')) - @build_list = BuildList.where(id: task['args'][0]['id']).first - end + @build_list = BuildList.next_build end - ActiveRecord::Base.transaction do - if current_user.system? - @build_list ||= build_lists.external_nodes(:everything).first - @build_list.touch if @build_list - else - @build_list = build_lists.external_nodes(:owned).for_user(current_user).first - @build_list ||= build_lists.external_nodes(:everything). - accessible_by(current_ability, :everything).readonly(false).first + unless @build_list + platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present? + arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present? + build_lists = BuildList.for_status(BuildList::BUILD_PENDING).scoped_to_arch(arch_ids). + oldest.order(:created_at) + build_lists = build_lists.for_platform(platform_ids) if platform_ids.present? - if @build_list - @build_list.builder = current_user - @build_list.save + ActiveRecord::Base.transaction do + if current_user.system? + @build_list ||= build_lists.external_nodes(:everything).first + @build_list.touch if @build_list + else + @build_list = build_lists.external_nodes(:owned).for_user(current_user).first + @build_list ||= build_lists.external_nodes(:everything). + accessible_by(current_ability, :everything).readonly(false).first + + if @build_list + @build_list.builder = current_user + @build_list.save + end end end - end unless @build_list - - if @build_list - job = { - worker_queue: @build_list.worker_queue_with_priority, - worker_class: @build_list.worker_queue_class, - :worker_args => [@build_list.abf_worker_args] - } end + + + job = { + worker_queue: @build_list.worker_queue_with_priority(false), + worker_class: @build_list.worker_queue_class, + :worker_args => [@build_list.abf_worker_args] + } if @build_list + render json: { job: job }.to_json end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index afaee0d10..1a020b244 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -522,6 +522,29 @@ class BuildList < ActiveRecord::Base ) end + def self.next_build + unless task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker')) + kind_id = Resque.redis.spop(USER_BUILDS_SET) + key = "user_build_#{kind_id}_rpm_worker_default" if kind_id + task = Resque.pop(key) if key + Resque.redis.sadd(USER_BUILDS_SET, kind_id) if task + + + kind_id ||= Resque.redis.spop(MASS_BUILDS_SET) + key ||= "mass_build_#{kind_id}_rpm_worker" if kind_id + task ||= Resque.pop(key) if key + Resque.redis.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/ + + Resque.redis.multi do + if Resque.redis.llen("queue:#{key}") == 0 + Resque.redis.del "queue:#{key}" + end + end if task + end + + BuildList.where(id: task['args'][0]['id']).first if task + end + protected def create_container diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index 2e7e2baac..9e0731680 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -299,8 +299,6 @@ module AbfWorker platform_path << '/' << build_for_platform.name system "mkdir -p #{platform_path}" end - worker_queue = bl ? bl.worker_queue_with_priority("publish_worker") : 'publish_worker_default' - worker_class = bl ? bl.worker_queue_class("AbfWorker::PublishWorker") : 'AbfWorker::PublishWorkerDefault' distrib_type = build_for_platform.distrib_type cmd_params = { @@ -350,9 +348,9 @@ module AbfWorker packages[:sources] = new_sources.values.compact Resque.push( - worker_queue, - 'class' => worker_class, - 'args' => [options.merge({ + 'publish_worker_default', + 'class' => 'AbfWorker::PublishWorkerDefault', + 'args' => [options.merge({ packages: packages, old_packages: old_packages, build_list_ids: build_list_ids, diff --git a/lib/abf_worker/model_helper.rb b/lib/abf_worker/model_helper.rb index 5ee7b8193..9931714d1 100644 --- a/lib/abf_worker/model_helper.rb +++ b/lib/abf_worker/model_helper.rb @@ -3,6 +3,9 @@ module AbfWorker::ModelHelper # - #abf_worker_args # - #build_canceled + MASS_BUILDS_SET = 'abf-worker::mass-builds' + USER_BUILDS_SET = 'abf-worker::user-builds' + def self.included(base) base.extend(ClassMethods) end @@ -14,6 +17,11 @@ module AbfWorker::ModelHelper port: APP_CONFIG['abf_worker']['log_server']['port'] ) end + + def self.next_build + raise NotImplementedError + end + end def abf_worker_log @@ -21,6 +29,7 @@ module AbfWorker::ModelHelper end def add_job_to_abf_worker_queue + update_build_sets Resque.push( worker_queue_with_priority, 'class' => worker_queue_class, @@ -29,8 +38,8 @@ module AbfWorker::ModelHelper end def restart_job - redis = Resque.redis - redis.lpush "queue:#{worker_queue_with_priority}", + update_build_sets + Resque.redis.lpush "queue:#{worker_queue_with_priority}", Resque.encode({'class' => worker_queue_class, 'args' => [abf_worker_args]}) end @@ -44,26 +53,63 @@ module AbfWorker::ModelHelper end def destroy_from_resque_queue - Resque::Job.destroy( + result = Resque::Job.destroy( worker_queue_with_priority, worker_queue_class, abf_worker_args ) + cleanup_build_sets + result end - def worker_queue_with_priority(queue = nil) - queue ||= abf_worker_base_queue + def worker_queue_with_priority(prefix = true) + queue = '' + + if prefix && is_a?(BuildList) + if mass_build_id + queue << "mass_build_#{mass_build_id}_" + else + queue << "user_build_#{user_id}_" + end + end + + queue << abf_worker_base_queue queue << '_' << abf_worker_priority if abf_worker_priority.present? queue end - def worker_queue_class(queue_class = nil) - queue_class ||= "AbfWorker::#{abf_worker_base_queue.classify}" - queue_class << abf_worker_priority.capitalize + def worker_queue_class + "AbfWorker::#{abf_worker_base_queue.classify}#{abf_worker_priority.capitalize}" end + private + def cleanup_build_sets + return unless is_a?(BuildList) + + if Resque.redis.llen("queue:#{worker_queue_with_priority}") == 0 + if mass_build_id + Resque.redis.srem MASS_BUILDS_SET, mass_build_id + else + Resque.redis.srem USER_BUILDS_SET, user_id + end + Resque.redis.del "queue:#{worker_queue_with_priority}" + end + + end + + def update_build_sets + return unless is_a?(BuildList) + + if mass_build_id + Resque.redis.sadd MASS_BUILDS_SET, mass_build_id + else + Resque.redis.sadd USER_BUILDS_SET, user_id + end + end + + def send_stop_signal Resque.redis.setex( "#{service_queue}::live-inspector", From 127553498f470378e2a179ebabccd54763121402 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 5 Feb 2014 02:49:19 +0400 Subject: [PATCH 02/34] Refactoring of abf_worker/model_helper --- lib/abf_worker/model_helper.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/abf_worker/model_helper.rb b/lib/abf_worker/model_helper.rb index 9931714d1..73ebb9d6f 100644 --- a/lib/abf_worker/model_helper.rb +++ b/lib/abf_worker/model_helper.rb @@ -86,27 +86,20 @@ module AbfWorker::ModelHelper private def cleanup_build_sets - return unless is_a?(BuildList) - - if Resque.redis.llen("queue:#{worker_queue_with_priority}") == 0 - if mass_build_id - Resque.redis.srem MASS_BUILDS_SET, mass_build_id - else - Resque.redis.srem USER_BUILDS_SET, user_id + Resque.redis.multi do + if Resque.redis.llen("queue:#{worker_queue_with_priority}") == 0 + key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET + Resque.redis.srem key, mass_build_id || user_id + Resque.redis.del "queue:#{worker_queue_with_priority}" end - Resque.redis.del "queue:#{worker_queue_with_priority}" - end - + end if is_a?(BuildList) end def update_build_sets return unless is_a?(BuildList) - if mass_build_id - Resque.redis.sadd MASS_BUILDS_SET, mass_build_id - else - Resque.redis.sadd USER_BUILDS_SET, user_id - end + key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET + Resque.redis.sadd key, mass_build_id || user_id end From f1323bf9bd42b2f4b82469734de6298d495d38bc Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 21 Feb 2014 22:20:05 +0400 Subject: [PATCH 03/34] Clean/restore queues --- app/models/build_list.rb | 18 +++++++++--------- lib/abf_worker/model_helper.rb | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 4e6e2e848..2359a7457 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -543,22 +543,22 @@ class BuildList < ActiveRecord::Base def self.next_build unless task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker')) - kind_id = Resque.redis.spop(USER_BUILDS_SET) + redis = Resque.redis + kind_id = redis.spop(USER_BUILDS_SET) key = "user_build_#{kind_id}_rpm_worker_default" if kind_id task = Resque.pop(key) if key - Resque.redis.sadd(USER_BUILDS_SET, kind_id) if task + redis.sadd(USER_BUILDS_SET, kind_id) if task - kind_id ||= Resque.redis.spop(MASS_BUILDS_SET) + kind_id ||= redis.spop(MASS_BUILDS_SET) key ||= "mass_build_#{kind_id}_rpm_worker" if kind_id task ||= Resque.pop(key) if key - Resque.redis.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/ + redis.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/ - Resque.redis.multi do - if Resque.redis.llen("queue:#{key}") == 0 - Resque.redis.del "queue:#{key}" - end - end if task + if task && redis.llen("queue:#{key}") == 0 + redis.del "queue:#{key}" + redis.srem 'queues', key + end end if task diff --git a/lib/abf_worker/model_helper.rb b/lib/abf_worker/model_helper.rb index 73ebb9d6f..ffb58833a 100644 --- a/lib/abf_worker/model_helper.rb +++ b/lib/abf_worker/model_helper.rb @@ -39,6 +39,7 @@ module AbfWorker::ModelHelper def restart_job update_build_sets + Resque.redis.sadd 'queues', worker_queue_with_priority Resque.redis.lpush "queue:#{worker_queue_with_priority}", Resque.encode({'class' => worker_queue_class, 'args' => [abf_worker_args]}) end From 8d178b856f5e1ebe2c93e1e9bdc3eb113194398a Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 21 Feb 2014 23:07:27 +0400 Subject: [PATCH 04/34] refactoring --- app/models/build_list.rb | 8 ++------ lib/abf_worker/model_helper.rb | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 2359a7457..7caed5549 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -189,7 +189,7 @@ class BuildList < ActiveRecord::Base # build_canceling: :build_canceled - canceling from UI # build_started: :build_canceled - canceling from worker by time-out (time_living has been expired) event :build_canceled do - transition [:build_canceling, :build_started] => :build_canceled + transition [:build_canceling, :build_started, :build_pending] => :build_canceled end event :published do @@ -554,15 +554,11 @@ class BuildList < ActiveRecord::Base key ||= "mass_build_#{kind_id}_rpm_worker" if kind_id task ||= Resque.pop(key) if key redis.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/ - - if task && redis.llen("queue:#{key}") == 0 - redis.del "queue:#{key}" - redis.srem 'queues', key - end end if task build_list = BuildList.where(id: task['args'][0]['id']).first + build_list.cleanup_build_sets build_list.delayed_add_job_to_abf_worker_queue build_list end diff --git a/lib/abf_worker/model_helper.rb b/lib/abf_worker/model_helper.rb index ffb58833a..8b32bfc58 100644 --- a/lib/abf_worker/model_helper.rb +++ b/lib/abf_worker/model_helper.rb @@ -39,7 +39,6 @@ module AbfWorker::ModelHelper def restart_job update_build_sets - Resque.redis.sadd 'queues', worker_queue_with_priority Resque.redis.lpush "queue:#{worker_queue_with_priority}", Resque.encode({'class' => worker_queue_class, 'args' => [abf_worker_args]}) end @@ -83,24 +82,26 @@ module AbfWorker::ModelHelper "AbfWorker::#{abf_worker_base_queue.classify}#{abf_worker_priority.capitalize}" end + def cleanup_build_sets + return unless is_a?(BuildList) + queue = worker_queue_with_priority + if Resque.redis.llen("queue:#{queue}") == 0 + key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET + Resque.redis.srem key, mass_build_id || user_id + Resque.redis.del "queue:#{queue}" + Resque.redis.srem 'queues', queue + end + end private - def cleanup_build_sets - Resque.redis.multi do - if Resque.redis.llen("queue:#{worker_queue_with_priority}") == 0 - key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET - Resque.redis.srem key, mass_build_id || user_id - Resque.redis.del "queue:#{worker_queue_with_priority}" - end - end if is_a?(BuildList) - end def update_build_sets return unless is_a?(BuildList) key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET Resque.redis.sadd key, mass_build_id || user_id + Resque.redis.sadd 'queues', worker_queue_with_priority end From fe20a9788a770d93633bda4681bdc580065778a9 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 25 Feb 2014 00:36:51 +0400 Subject: [PATCH 05/34] Use resque-schedule for cleanup --- .../build_lists_publish_task_manager_job.rb | 8 ++++++++ app/jobs/clean_build_lists_queues_job.rb | 18 +++++++++++++++++ app/jobs/clean_rpm_build_node_job.rb | 10 ++++++++++ app/models/build_list.rb | 1 - app/models/rpm_build_node.rb | 6 ------ config/application.rb | 1 + config/initializers/resque.rb | 1 + config/resque_schedule.yml | 20 +++++++++++++++++++ config/schedule.rb | 8 -------- lib/abf_worker/model_helper.rb | 12 ----------- 10 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 app/jobs/build_lists_publish_task_manager_job.rb create mode 100644 app/jobs/clean_build_lists_queues_job.rb create mode 100644 app/jobs/clean_rpm_build_node_job.rb create mode 100644 config/resque_schedule.yml diff --git a/app/jobs/build_lists_publish_task_manager_job.rb b/app/jobs/build_lists_publish_task_manager_job.rb new file mode 100644 index 000000000..1fc5dca83 --- /dev/null +++ b/app/jobs/build_lists_publish_task_manager_job.rb @@ -0,0 +1,8 @@ +class BuildListsPublishTaskManagerJob + @queue = :hook + + def self.perform + AbfWorker::BuildListsPublishTaskManager.new.run + end + +end diff --git a/app/jobs/clean_build_lists_queues_job.rb b/app/jobs/clean_build_lists_queues_job.rb new file mode 100644 index 000000000..853c523b4 --- /dev/null +++ b/app/jobs/clean_build_lists_queues_job.rb @@ -0,0 +1,18 @@ +class CleanBuildListsQueuesJob + @queue = :hook + + def self.perform + redis = Resque.redis + redis.smembers('queues').each do |key| + next if key !~ /(user|mass)_build_/ + queue = "queue:#{key}" + if redis.llen(queue) == 0 + redis.multi do + redis.del queue + redis.srem 'queues', key + end + end + end + end + +end diff --git a/app/jobs/clean_rpm_build_node_job.rb b/app/jobs/clean_rpm_build_node_job.rb new file mode 100644 index 000000000..67c2f212e --- /dev/null +++ b/app/jobs/clean_rpm_build_node_job.rb @@ -0,0 +1,10 @@ +class CleanRpmBuildNodeJob + @queue = :hook + + def self.perform + RpmBuildNode.all.each do |n| + n.delete unless n.user_id + end + end + +end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 7caed5549..561345a18 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -558,7 +558,6 @@ class BuildList < ActiveRecord::Base if task build_list = BuildList.where(id: task['args'][0]['id']).first - build_list.cleanup_build_sets build_list.delayed_add_job_to_abf_worker_queue build_list end diff --git a/app/models/rpm_build_node.rb b/app/models/rpm_build_node.rb index f03a5b161..c9a95f6bb 100644 --- a/app/models/rpm_build_node.rb +++ b/app/models/rpm_build_node.rb @@ -17,12 +17,6 @@ class RpmBuildNode < Ohm::Model User.where(id: user_id).first end - def self.cleanup! - RpmBuildNode.all.each do |n| - n.delete unless n.user_id - end - end - def self.total_statistics systems, others, busy = 0, 0, 0 RpmBuildNode.all.select{ |n| n.user_id }.each do |n| diff --git a/config/application.rb b/config/application.rb index e59074d7e..fc556a46e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -27,6 +27,7 @@ module Rosa # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) config.autoload_paths += %W(#{config.root}/app/presenters) + config.autoload_paths += %W(#{config.root}/app/jobs) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index f2c69e5c3..b810398ec 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -10,6 +10,7 @@ Resque::Mailer.excluded_environments = [:test] unless Rails.env.test? PerformLater.config.enabled = true # this will default to false if unset + Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule end Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml new file mode 100644 index 000000000..1c443b286 --- /dev/null +++ b/config/resque_schedule.yml @@ -0,0 +1,20 @@ +clean_rpm_build_nodes: + every: + - '1m' + class: 'CleanRpmBuildNodeJob' + queue: hook + description: 'Cleans RPM build nodes' + +build_lists_publish_task_manager: + every: + - '3m' + class: 'BuildListsPublishTaskManagerJob' + queue: hook + description: 'Creates tasks for publishing' + +clean_build_lists_queues: + every: + - '1m' + class: 'CleanBuildListsQueuesJob' + queue: hook + description: 'Cleans build_lists queues' \ No newline at end of file diff --git a/config/schedule.rb b/config/schedule.rb index b0b7e6031..320b7603e 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -26,14 +26,6 @@ every :day, at: '3:00 am' do rake 'activity_feeds:clear', output: 'log/activity_feeds.log' end -every 3.minute do - runner 'AbfWorker::BuildListsPublishTaskManager.new.run', output: 'log/task_manager.log' -end - -every 1.minute do - runner 'RpmBuildNode.cleanup!' -end - every 1.hour do rake 'buildlist:clear:outdated_canceling', output: 'log/canceling_build_list_clear.log' end diff --git a/lib/abf_worker/model_helper.rb b/lib/abf_worker/model_helper.rb index 8b32bfc58..9fc717a17 100644 --- a/lib/abf_worker/model_helper.rb +++ b/lib/abf_worker/model_helper.rb @@ -58,7 +58,6 @@ module AbfWorker::ModelHelper worker_queue_class, abf_worker_args ) - cleanup_build_sets result end @@ -82,17 +81,6 @@ module AbfWorker::ModelHelper "AbfWorker::#{abf_worker_base_queue.classify}#{abf_worker_priority.capitalize}" end - def cleanup_build_sets - return unless is_a?(BuildList) - queue = worker_queue_with_priority - if Resque.redis.llen("queue:#{queue}") == 0 - key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET - Resque.redis.srem key, mass_build_id || user_id - Resque.redis.del "queue:#{queue}" - Resque.redis.srem 'queues', queue - end - end - private From 4838d5e0b873e5b99060611e6461da238447f6e7 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 25 Feb 2014 00:59:20 +0400 Subject: [PATCH 06/34] Cleanup, refactoring, updated transaction --- app/jobs/clean_build_lists_queues_job.rb | 1 + lib/abf_worker/model_helper.rb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/jobs/clean_build_lists_queues_job.rb b/app/jobs/clean_build_lists_queues_job.rb index 853c523b4..f3d41c247 100644 --- a/app/jobs/clean_build_lists_queues_job.rb +++ b/app/jobs/clean_build_lists_queues_job.rb @@ -8,6 +8,7 @@ class CleanBuildListsQueuesJob queue = "queue:#{key}" if redis.llen(queue) == 0 redis.multi do + redis.watch queue redis.del queue redis.srem 'queues', key end diff --git a/lib/abf_worker/model_helper.rb b/lib/abf_worker/model_helper.rb index 9fc717a17..98d19e93d 100644 --- a/lib/abf_worker/model_helper.rb +++ b/lib/abf_worker/model_helper.rb @@ -53,12 +53,11 @@ module AbfWorker::ModelHelper end def destroy_from_resque_queue - result = Resque::Job.destroy( + Resque::Job.destroy( worker_queue_with_priority, worker_queue_class, abf_worker_args ) - result end def worker_queue_with_priority(prefix = true) @@ -88,8 +87,10 @@ module AbfWorker::ModelHelper return unless is_a?(BuildList) key = mass_build_id ? MASS_BUILDS_SET : USER_BUILDS_SET - Resque.redis.sadd key, mass_build_id || user_id - Resque.redis.sadd 'queues', worker_queue_with_priority + Resque.redis.pipelined do + Resque.redis.sadd key, mass_build_id || user_id + Resque.redis.sadd 'queues', worker_queue_with_priority + end end From c5e3c7121e8aef0c68cf0fbf02e5f1d51d7aa1fe Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 25 Feb 2014 23:19:41 +0400 Subject: [PATCH 07/34] Updated therubyracer --- Gemfile | 2 +- Gemfile.lock | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 6729fabae..29f1b5617 100644 --- a/Gemfile +++ b/Gemfile @@ -84,7 +84,7 @@ group :assets do gem 'coffee-rails', '~> 3.2.2' gem 'compass-rails', '~> 1.0.3' gem 'uglifier', '~> 1.2.4' - gem 'therubyracer', '~> 0.10.2', platforms: [:mri, :rbx] + gem 'therubyracer', '~> 0.12.1', platforms: [:mri, :rbx] gem 'therubyrhino', '~> 1.73.1', platforms: :jruby gem 'turbo-sprockets-rails3' end diff --git a/Gemfile.lock b/Gemfile.lock index 858ab75a7..b8f00f6bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -192,7 +192,7 @@ GEM json (1.8.1) jwt (0.1.10) multi_json (>= 1.5) - libv8 (3.3.10.4) + libv8 (3.16.14.3) localeapp (0.6.14) gli i18n @@ -342,6 +342,7 @@ GEM redisk (0.2.2) redis (>= 0.1.1) redis-namespace (>= 0.1.0) + ref (1.0.5) resque (1.25.1) mono_logger (~> 1.0) multi_json (~> 1.0) @@ -420,8 +421,9 @@ GEM state_machine (1.2.0) stringex (1.4.0) systemu (2.5.2) - therubyracer (0.10.2) - libv8 (~> 3.3.10) + therubyracer (0.12.1) + libv8 (~> 3.16.14.0) + ref thin (1.5.1) daemons (>= 1.0.9) eventmachine (>= 0.12.6) @@ -540,7 +542,7 @@ DEPENDENCIES shoulda soundmanager-rails state_machine - therubyracer (~> 0.10.2) + therubyracer (~> 0.12.1) therubyrhino (~> 1.73.1) time_diff trinidad (~> 1.0.2) From 85023f415c84c98f724322ef47cb6276311d734f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 00:41:13 +0400 Subject: [PATCH 08/34] Reconect to redis --- config/initializers/resque.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index b810398ec..ed9a90705 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -14,3 +14,7 @@ unless Rails.env.test? end Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds + +Resque.after_fork do |job| + Resque.redis.client.reconnect +end \ No newline at end of file From 7919fb955bf71026ec916deb660a717ea08300af Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 00:47:51 +0400 Subject: [PATCH 09/34] rollback changes --- config/initializers/resque.rb | 4 ---- lib/recipes/resque.rb | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index ed9a90705..b810398ec 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -14,7 +14,3 @@ unless Rails.env.test? end Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds - -Resque.after_fork do |job| - Resque.redis.client.reconnect -end \ No newline at end of file diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index afae87b5a..049d0b98d 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -14,6 +14,12 @@ Capistrano::Configuration.instance(:must_exist).load do start_workers end + task :setup => :environment do + Resque.after_fork do + Resque.redis.client.reconnect + end + end + def rails_env fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : '' end From a18703242c2522ab55d690d7edb21d9a48679afd Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 00:49:51 +0400 Subject: [PATCH 10/34] rollback changes --- lib/recipes/resque.rb | 6 ------ lib/tasks/resque.rake | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index 049d0b98d..afae87b5a 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -14,12 +14,6 @@ Capistrano::Configuration.instance(:must_exist).load do start_workers end - task :setup => :environment do - Resque.after_fork do - Resque.redis.client.reconnect - end - end - def rails_env fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : '' end diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 13c8f72f5..07ee2f50f 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -7,4 +7,11 @@ namespace :resque do end system("kill -QUIT #{pids.join(' ')}") if pids.size > 0 end + + task setup: :environment do + Resque.after_fork do + Resque.redis.client.reconnect + end + end + end From bcc841033c35d158b22a21dcc5607963cd522d16 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 01:15:40 +0400 Subject: [PATCH 11/34] Updated initializers --- config/initializers/{a_app_config.rb => 0_app_config.rb} | 0 config/initializers/{resque.rb => 1_resque.rb} | 2 ++ lib/tasks/resque.rake | 3 +++ 3 files changed, 5 insertions(+) rename config/initializers/{a_app_config.rb => 0_app_config.rb} (100%) rename config/initializers/{resque.rb => 1_resque.rb} (88%) diff --git a/config/initializers/a_app_config.rb b/config/initializers/0_app_config.rb similarity index 100% rename from config/initializers/a_app_config.rb rename to config/initializers/0_app_config.rb diff --git a/config/initializers/resque.rb b/config/initializers/1_resque.rb similarity index 88% rename from config/initializers/resque.rb rename to config/initializers/1_resque.rb index b810398ec..44afe5ee1 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/1_resque.rb @@ -14,3 +14,5 @@ unless Rails.env.test? end Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds + +Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } \ No newline at end of file diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 07ee2f50f..e0a781848 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -1,3 +1,5 @@ +require 'resque/tasks' + namespace :resque do desc 'Stop all Resque workers' task stop_workers: :environment do @@ -12,6 +14,7 @@ namespace :resque do Resque.after_fork do Resque.redis.client.reconnect end + Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end end From c54225ec034baaaab1c39b1db1c404dfc1b0c754 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 01:21:10 +0400 Subject: [PATCH 12/34] Rollback changes --- config/initializers/1_resque.rb | 5 ++++- lib/tasks/resque.rake | 10 ---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/config/initializers/1_resque.rb b/config/initializers/1_resque.rb index 44afe5ee1..07d6ca6fd 100644 --- a/config/initializers/1_resque.rb +++ b/config/initializers/1_resque.rb @@ -15,4 +15,7 @@ end Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds -Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } \ No newline at end of file +Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } +Resque.after_fork do + Resque.redis.client.reconnect +end \ No newline at end of file diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index e0a781848..13c8f72f5 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -1,5 +1,3 @@ -require 'resque/tasks' - namespace :resque do desc 'Stop all Resque workers' task stop_workers: :environment do @@ -9,12 +7,4 @@ namespace :resque do end system("kill -QUIT #{pids.join(' ')}") if pids.size > 0 end - - task setup: :environment do - Resque.after_fork do - Resque.redis.client.reconnect - end - Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } - end - end From 092bc10b2c585542bc2b110ee9477eecbded9853 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 01:51:11 +0400 Subject: [PATCH 13/34] cleanup --- Rakefile | 6 ++++++ config/initializers/1_resque.rb | 8 +------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 31c005551..bcaf13e41 100644 --- a/Rakefile +++ b/Rakefile @@ -8,6 +8,12 @@ require 'resque_scheduler/tasks' # This fixes connection fail with Postgres server on new fork: task "resque:setup" => :environment do + require 'resque' + require 'resque-scheduler' + Resque.after_fork do + Resque.redis.client.reconnect + Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule + end Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end diff --git a/config/initializers/1_resque.rb b/config/initializers/1_resque.rb index 07d6ca6fd..0c51c5ef6 100644 --- a/config/initializers/1_resque.rb +++ b/config/initializers/1_resque.rb @@ -10,12 +10,6 @@ Resque::Mailer.excluded_environments = [:test] unless Rails.env.test? PerformLater.config.enabled = true # this will default to false if unset - Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule end -Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds - -Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } -Resque.after_fork do - Resque.redis.client.reconnect -end \ No newline at end of file +Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds \ No newline at end of file From d02317b6f6d513949bdf4fc2d6ccbdaf7380a81c Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 01:52:30 +0400 Subject: [PATCH 14/34] cleanup 2 --- Rakefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Rakefile b/Rakefile index bcaf13e41..10e9cd050 100644 --- a/Rakefile +++ b/Rakefile @@ -8,8 +8,6 @@ require 'resque_scheduler/tasks' # This fixes connection fail with Postgres server on new fork: task "resque:setup" => :environment do - require 'resque' - require 'resque-scheduler' Resque.after_fork do Resque.redis.client.reconnect Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule From 4a881f7a1967e66b87df5c6a32db0c52455dc52d Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 02:27:29 +0400 Subject: [PATCH 15/34] Fixed: nil can't be coerced into Fixnum --- app/models/build_list_observer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/build_list_observer.rb b/app/models/build_list_observer.rb index 59b51499f..e59ae493f 100644 --- a/app/models/build_list_observer.rb +++ b/app/models/build_list_observer.rb @@ -19,7 +19,7 @@ class BuildListObserver < ActiveRecord::Observer rescue ActiveRecord::RecordNotUnique retry end - build_count = statistic.build_count + build_count = statistic.build_count.to_i new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 ) statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1) end From 1e721a863f550180c3c1984f777a92df84131989 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 02:40:48 +0400 Subject: [PATCH 16/34] Disable cleaning, fixed: nil can't be coerced into Fixnum --- app/models/build_list_observer.rb | 2 +- config/resque_schedule.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/build_list_observer.rb b/app/models/build_list_observer.rb index e59ae493f..aa4662772 100644 --- a/app/models/build_list_observer.rb +++ b/app/models/build_list_observer.rb @@ -20,7 +20,7 @@ class BuildListObserver < ActiveRecord::Observer retry end build_count = statistic.build_count.to_i - new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 ) + new_av_time = ( statistic.average_build_time * build_count + record.duration.to_i ) / ( build_count + 1 ) statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1) end end diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 1c443b286..7260348d4 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -12,9 +12,9 @@ build_lists_publish_task_manager: queue: hook description: 'Creates tasks for publishing' -clean_build_lists_queues: - every: - - '1m' - class: 'CleanBuildListsQueuesJob' - queue: hook - description: 'Cleans build_lists queues' \ No newline at end of file +# clean_build_lists_queues: +# every: +# - '1m' +# class: 'CleanBuildListsQueuesJob' +# queue: hook +# description: 'Cleans build_lists queues' \ No newline at end of file From ccd32a4eb2d7cffe7ad5e5f9a302645b2113e425 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 02:57:36 +0400 Subject: [PATCH 17/34] Updated status_inspector --- lib/abf_worker/status_inspector.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/abf_worker/status_inspector.rb b/lib/abf_worker/status_inspector.rb index 8edadee12..5743ca8ba 100644 --- a/lib/abf_worker/status_inspector.rb +++ b/lib/abf_worker/status_inspector.rb @@ -9,13 +9,21 @@ module AbfWorker result[:rpm][:workers] += nodes[:systems] result[:rpm][:build_tasks] += nodes[:busy] result[:rpm][:other_workers] = nodes[:others] + external_bls = BuildList.for_status(BuildList::BUILD_PENDING).external_nodes(:everything).count - result[:rpm][:default_tasks] += external_bls - result[:rpm][:tasks] += external_bls + result[:rpm][:default_tasks] += external_bls + count_of_tasks('user_build_') + + result[:rpm][:tasks] += external_bls + count_of_tasks('mass_build_') result end end + def count_of_tasks(regexp) + Resque.redis.smembers('queues'). + select{ |q| q =~ /#{regexp}/ }. + map{ |q| Resque.redis.llen("queue:#{q}") }.sum + end + def products_status get_status(:iso) { |w, worker| str = w.to_s From 139dc177d4da14cef773d1144bfe37b42f4621c9 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 13:22:55 +0400 Subject: [PATCH 18/34] Rollback schedule.rb --- Rakefile | 2 +- config/schedule.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 10e9cd050..05eb30807 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ require 'resque_scheduler/tasks' task "resque:setup" => :environment do Resque.after_fork do Resque.redis.client.reconnect - Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule + # Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule end Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end diff --git a/config/schedule.rb b/config/schedule.rb index 9e9cb2b29..0d04267e2 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -26,6 +26,14 @@ every :day, at: '3:00 am' do rake 'activity_feeds:clear', output: 'log/activity_feeds.log' end +every 3.minute do + runner 'AbfWorker::BuildListsPublishTaskManager.new.run', output: 'log/task_manager.log' +end + +every 1.minute do + runner 'RpmBuildNode.cleanup!' +end + every 1.hour do rake 'buildlist:clear:outdated_canceling', output: 'log/canceling_build_list_clear.log' end From db3ba727e90e3e4df5023b15efc170523bc5dd2a Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Feb 2014 19:06:46 +0400 Subject: [PATCH 19/34] Fixed: build_lists statistics --- lib/abf_worker/status_inspector.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/abf_worker/status_inspector.rb b/lib/abf_worker/status_inspector.rb index 5743ca8ba..d21c115c2 100644 --- a/lib/abf_worker/status_inspector.rb +++ b/lib/abf_worker/status_inspector.rb @@ -13,7 +13,9 @@ module AbfWorker external_bls = BuildList.for_status(BuildList::BUILD_PENDING).external_nodes(:everything).count result[:rpm][:default_tasks] += external_bls + count_of_tasks('user_build_') - result[:rpm][:tasks] += external_bls + count_of_tasks('mass_build_') + mass_build_tasks = count_of_tasks('mass_build_') + result[:rpm][:low_tasks] += mass_build_tasks + result[:rpm][:tasks] += external_bls + mass_build_tasks result end end From f8ba1d05a068c020bf11566a5a276fe5ccd01096 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 00:50:39 +0400 Subject: [PATCH 20/34] Cleanup --- Gemfile.lock | 4 ++-- Rakefile | 9 --------- app/models/build_list.rb | 20 +++++++++----------- config/schedule.rb | 8 -------- lib/tasks/resque.rake | 13 +++++++++++++ 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b8f00f6bd..a186dc444 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -320,7 +320,7 @@ GEM rdoc (3.12.2) json (~> 1.4) redcarpet (2.2.2) - redis (3.0.6) + redis (3.0.7) redis-actionpack (3.2.4) actionpack (~> 3.2.0) redis-rack (~> 1.4.4) @@ -349,7 +349,7 @@ GEM redis-namespace (~> 1.2) sinatra (>= 0.9.2) vegas (~> 0.1.2) - resque-scheduler (2.5.3) + resque-scheduler (2.5.4) redis (~> 3.0.4) resque (~> 1.25.1) rufus-scheduler (~> 2.0.24) diff --git a/Rakefile b/Rakefile index 05eb30807..562c9b3d7 100644 --- a/Rakefile +++ b/Rakefile @@ -6,13 +6,4 @@ require 'rake' require 'resque/tasks' require 'resque_scheduler/tasks' -# This fixes connection fail with Postgres server on new fork: -task "resque:setup" => :environment do - Resque.after_fork do - Resque.redis.client.reconnect - # Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml')) # load the schedule - end - Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } -end - Rosa::Application.load_tasks diff --git a/app/models/build_list.rb b/app/models/build_list.rb index ad743266f..78976b241 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -527,19 +527,17 @@ class BuildList < ActiveRecord::Base end def self.next_build - unless task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker')) - redis = Resque.redis - kind_id = redis.spop(USER_BUILDS_SET) - key = "user_build_#{kind_id}_rpm_worker_default" if kind_id - task = Resque.pop(key) if key - redis.sadd(USER_BUILDS_SET, kind_id) if task + redis = Resque.redis + kind_id = redis.spop(USER_BUILDS_SET) + key = "user_build_#{kind_id}_rpm_worker_default" if kind_id + task = Resque.pop(key) if key + redis.sadd(USER_BUILDS_SET, kind_id) if task - kind_id ||= redis.spop(MASS_BUILDS_SET) - key ||= "mass_build_#{kind_id}_rpm_worker" if kind_id - task ||= Resque.pop(key) if key - redis.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/ - end + kind_id ||= redis.spop(MASS_BUILDS_SET) + key ||= "mass_build_#{kind_id}_rpm_worker" if kind_id + task ||= Resque.pop(key) if key + redis.sadd(MASS_BUILDS_SET, kind_id) if task && key =~ /^mass_build/ if task build_list = BuildList.where(id: task['args'][0]['id']).first diff --git a/config/schedule.rb b/config/schedule.rb index 0d04267e2..9e9cb2b29 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -26,14 +26,6 @@ every :day, at: '3:00 am' do rake 'activity_feeds:clear', output: 'log/activity_feeds.log' end -every 3.minute do - runner 'AbfWorker::BuildListsPublishTaskManager.new.run', output: 'log/task_manager.log' -end - -every 1.minute do - runner 'RpmBuildNode.cleanup!' -end - every 1.hour do rake 'buildlist:clear:outdated_canceling', output: 'log/canceling_build_list_clear.log' end diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 13c8f72f5..76cafb58a 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -7,4 +7,17 @@ namespace :resque do end system("kill -QUIT #{pids.join(' ')}") if pids.size > 0 end + + # This fixes connection fail with Postgres server on new fork: + task setup: :environment do + Resque.after_fork do + Resque.redis.client.reconnect + end + Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } + end + + task scheduler_setup: :environment do + Resque.schedule = YAML.load_file(Rails.root.join('config', 'resque_schedule.yml')) + end + end From ca6be1572ec5ff0dbf1c264935f90eeae24a8b0b Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 01:02:48 +0400 Subject: [PATCH 21/34] Set RESQUE_SCHEDULER_INTERVAL to 0.5s --- lib/recipes/resque.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index afae87b5a..3ffbb70dd 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -68,7 +68,7 @@ Capistrano::Configuration.instance(:must_exist).load do def start_scheduler pid = "#{fetch :current_path}/tmp/pids/scheduler.pid" - run "cd #{fetch :current_path} && #{rails_env} PIDFILE=#{pid} BACKGROUND=yes VERBOSE=1 MUTE=1 bundle exec rake resque:scheduler" + run "cd #{fetch :current_path} && #{rails_env} PIDFILE=#{pid} BACKGROUND=yes VERBOSE=1 MUTE=1 RESQUE_SCHEDULER_INTERVAL=0.5 bundle exec rake resque:scheduler" end def stop_scheduler From 8dc8f2abb81fecea0da17258ecd3d42bf240079c Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 01:27:54 +0400 Subject: [PATCH 22/34] Updated CleanBuildListsQueuesJob --- app/jobs/clean_build_lists_queues_job.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/jobs/clean_build_lists_queues_job.rb b/app/jobs/clean_build_lists_queues_job.rb index f3d41c247..921ad7b54 100644 --- a/app/jobs/clean_build_lists_queues_job.rb +++ b/app/jobs/clean_build_lists_queues_job.rb @@ -6,7 +6,10 @@ class CleanBuildListsQueuesJob redis.smembers('queues').each do |key| next if key !~ /(user|mass)_build_/ queue = "queue:#{key}" - if redis.llen(queue) == 0 + last_updated_at = BuildList.where(user_id: key.gsub(/[^\d]/, '')). + order('updated_at DESC').limit(1).pluck(:updated_at).first + last_updated_at += 5.minutes if last_updated_at + if redis.llen(queue) == 0 && (!last_updated_at || last_updated_at < Time.zone.now) redis.multi do redis.watch queue redis.del queue From 813ac91a9987cac3c8f59afcb7f44214b6760463 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 22:51:57 +0400 Subject: [PATCH 23/34] Added BuildListsQueuesMonitoringJob --- app/jobs/build_lists_queues_monitoring_job.rb | 40 +++++++++++++++++++ app/jobs/clean_build_lists_queues_job.rb | 22 ---------- config/resque_schedule.yml | 12 +++--- 3 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 app/jobs/build_lists_queues_monitoring_job.rb delete mode 100644 app/jobs/clean_build_lists_queues_job.rb diff --git a/app/jobs/build_lists_queues_monitoring_job.rb b/app/jobs/build_lists_queues_monitoring_job.rb new file mode 100644 index 000000000..d7bcbbb83 --- /dev/null +++ b/app/jobs/build_lists_queues_monitoring_job.rb @@ -0,0 +1,40 @@ +class BuildListsQueuesMonitoringJob + @queue = :hook + + def self.perform + redis = Resque.redis + redis.smembers('queues').each do |key| + next if key !~ /(user|mass)_build_/ + + queue = "queue:#{key}" + id = key.gsub(/[^\d]/, '') + + if redis.llen(queue) == 0 + if key =~ /^user/ + last_updated_at = BuildList.select(:updated_at). + where(user_id: id).order('updated_at DESC').first + else + last_updated_at = MassBuild.select(:updated_at).where(id: 250).first + end + last_updated_at = last_updated_at.try(:updated_at) + # cleans queue if no activity and tasks for this queue + clean(key, !last_updated_at || (last_updated_at + 5.minutes) < Time.zone.now) + else + # ensures that user/mass-build in the set from which we select next jobs + set_key = key =~ /^user/ ? BuildList::USER_BUILDS_SET : BuildList::MASS_BUILDS_SET + redis.sadd set_key, id + end + + end + end + + def self.clean(key, and_condition) + queue = "queue:#{key}" + redis.multi do + redis.watch queue + redis.del queue + redis.srem 'queues', key + end if redis.llen(queue) == 0 && and_condition + end + +end diff --git a/app/jobs/clean_build_lists_queues_job.rb b/app/jobs/clean_build_lists_queues_job.rb deleted file mode 100644 index 921ad7b54..000000000 --- a/app/jobs/clean_build_lists_queues_job.rb +++ /dev/null @@ -1,22 +0,0 @@ -class CleanBuildListsQueuesJob - @queue = :hook - - def self.perform - redis = Resque.redis - redis.smembers('queues').each do |key| - next if key !~ /(user|mass)_build_/ - queue = "queue:#{key}" - last_updated_at = BuildList.where(user_id: key.gsub(/[^\d]/, '')). - order('updated_at DESC').limit(1).pluck(:updated_at).first - last_updated_at += 5.minutes if last_updated_at - if redis.llen(queue) == 0 && (!last_updated_at || last_updated_at < Time.zone.now) - redis.multi do - redis.watch queue - redis.del queue - redis.srem 'queues', key - end - end - end - end - -end diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 7260348d4..2a90a140a 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -12,9 +12,9 @@ build_lists_publish_task_manager: queue: hook description: 'Creates tasks for publishing' -# clean_build_lists_queues: -# every: -# - '1m' -# class: 'CleanBuildListsQueuesJob' -# queue: hook -# description: 'Cleans build_lists queues' \ No newline at end of file +clean_build_lists_queues: + every: + - '1m' + class: 'BuildListsQueuesMonitoringJob' + queue: hook + description: 'Cleans build_lists queues' \ No newline at end of file From d2873c79d5bfafe97feb8f7b19ca14f8e0e27275 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 22:56:40 +0400 Subject: [PATCH 24/34] Updated description --- config/resque_schedule.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 2a90a140a..243c866f5 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -17,4 +17,4 @@ clean_build_lists_queues: - '1m' class: 'BuildListsQueuesMonitoringJob' queue: hook - description: 'Cleans build_lists queues' \ No newline at end of file + description: 'Monitoring for "user/mass-build" queues' \ No newline at end of file From 4bde41588a92d9e6af893b2767749f02799eb51d Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 23:00:52 +0400 Subject: [PATCH 25/34] refactoring --- app/jobs/build_lists_queues_monitoring_job.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/jobs/build_lists_queues_monitoring_job.rb b/app/jobs/build_lists_queues_monitoring_job.rb index d7bcbbb83..fa43d22a1 100644 --- a/app/jobs/build_lists_queues_monitoring_job.rb +++ b/app/jobs/build_lists_queues_monitoring_job.rb @@ -2,7 +2,6 @@ class BuildListsQueuesMonitoringJob @queue = :hook def self.perform - redis = Resque.redis redis.smembers('queues').each do |key| next if key !~ /(user|mass)_build_/ @@ -37,4 +36,8 @@ class BuildListsQueuesMonitoringJob end if redis.llen(queue) == 0 && and_condition end + def self.redis + @redis ||= Resque.redis + end + end From 5b154445432d9cc9bce4d6f1881b456550f10992 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 23:25:37 +0400 Subject: [PATCH 26/34] Fixed: cleaning of old queues --- app/jobs/build_lists_queues_monitoring_job.rb | 19 ++++++++++++------- config/resque_schedule.yml | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/jobs/build_lists_queues_monitoring_job.rb b/app/jobs/build_lists_queues_monitoring_job.rb index fa43d22a1..6b3f429b3 100644 --- a/app/jobs/build_lists_queues_monitoring_job.rb +++ b/app/jobs/build_lists_queues_monitoring_job.rb @@ -17,7 +17,7 @@ class BuildListsQueuesMonitoringJob end last_updated_at = last_updated_at.try(:updated_at) # cleans queue if no activity and tasks for this queue - clean(key, !last_updated_at || (last_updated_at + 5.minutes) < Time.zone.now) + clean(key) if !last_updated_at || (last_updated_at + 5.minutes) < Time.zone.now else # ensures that user/mass-build in the set from which we select next jobs set_key = key =~ /^user/ ? BuildList::USER_BUILDS_SET : BuildList::MASS_BUILDS_SET @@ -27,13 +27,18 @@ class BuildListsQueuesMonitoringJob end end - def self.clean(key, and_condition) + def self.clean(key) queue = "queue:#{key}" - redis.multi do - redis.watch queue - redis.del queue - redis.srem 'queues', key - end if redis.llen(queue) == 0 && and_condition + redis.watch(queue) do + if redis.llen(queue) == 0 + redis.multi do |multi| + multi.del queue + multi.srem 'queues', key + end + else + redis.unwatch + end + end end def self.redis diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 243c866f5..60cd0e700 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -12,7 +12,7 @@ build_lists_publish_task_manager: queue: hook description: 'Creates tasks for publishing' -clean_build_lists_queues: +build_lists_queues_monitoring: every: - '1m' class: 'BuildListsQueuesMonitoringJob' From 46ed8d0f0f59b4ad28d41190070139e7fb73293c Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 27 Feb 2014 23:31:30 +0400 Subject: [PATCH 27/34] Added comment --- app/jobs/build_lists_queues_monitoring_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/build_lists_queues_monitoring_job.rb b/app/jobs/build_lists_queues_monitoring_job.rb index 6b3f429b3..7c10d4b2f 100644 --- a/app/jobs/build_lists_queues_monitoring_job.rb +++ b/app/jobs/build_lists_queues_monitoring_job.rb @@ -29,6 +29,7 @@ class BuildListsQueuesMonitoringJob def self.clean(key) queue = "queue:#{key}" + # See [#watch]: https://github.com/redis/redis-rb/blob/master/lib/redis.rb#L2012 redis.watch(queue) do if redis.llen(queue) == 0 redis.multi do |multi| From d5f7957447f9cbdc8caa130316761b2616229004 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 4 Mar 2014 16:46:10 +0600 Subject: [PATCH 28/34] [#247] remove related models --- app/controllers/groups/members_controller.rb | 21 +++-- app/views/groups/members/index.html.haml | 6 +- lib/plugins/related_models/base.rb | 23 ------ .../related_models/belongs_to_helpers.rb | 39 --------- lib/plugins/related_models/class_methods.rb | 68 ---------------- .../related_models/polymorphic_helpers.rb | 80 ------------------- lib/plugins/related_models/url_helpers.rb | 28 ------- 7 files changed, 12 insertions(+), 253 deletions(-) delete mode 100644 lib/plugins/related_models/base.rb delete mode 100644 lib/plugins/related_models/belongs_to_helpers.rb delete mode 100644 lib/plugins/related_models/class_methods.rb delete mode 100644 lib/plugins/related_models/polymorphic_helpers.rb delete mode 100644 lib/plugins/related_models/url_helpers.rb diff --git a/app/controllers/groups/members_controller.rb b/app/controllers/groups/members_controller.rb index 8dba574a5..2493e719f 100644 --- a/app/controllers/groups/members_controller.rb +++ b/app/controllers/groups/members_controller.rb @@ -1,7 +1,4 @@ class Groups::MembersController < Groups::BaseController - is_related_controller! - belongs_to :group, finder: 'find_by_insensitive_uname!', optional: true - before_filter lambda { authorize! :manage_members, @group } def index @@ -10,19 +7,19 @@ class Groups::MembersController < Groups::BaseController def update params['user'].keys.each do |user_id| role = params['user'][user_id] - if relation = parent.actors.where(actor_id: user_id, actor_type: 'User') #find_by_actor_id_and_actor_type(user_id, 'User') - relation.update_all(role: role) if parent.owner.id.to_s != user_id + if relation = @group.actors.where(actor_id: user_id, actor_type: 'User') #find_by_actor_id_and_actor_type(user_id, 'User') + relation.update_all(role: role) if @group.owner.id.to_s != user_id else - relation = parent.actors.build(actor_id: user_id, actor_type: 'User', role: role) + relation = @group.actors.build(actor_id: user_id, actor_type: 'User', role: role) relation.save! end end if params['user'] - if parent.save + if @group.save flash[:notice] = t("flash.members.successfully_changed") else flash[:error] = t("flash.members.error_in_changing") end - redirect_to group_members_path(parent) + redirect_to group_members_path(@group) end def remove @@ -31,20 +28,20 @@ class Groups::MembersController < Groups::BaseController all_user_ids << user_id if remove == ["1"] end if params['user_remove'] User.where(id: all_user_ids).each do |user| - parent.remove_member(user) + @group.remove_member(user) end - redirect_to group_members_path(parent) + redirect_to group_members_path(@group) end def add @user = User.find_by_uname(params[:user_uname]) if !@user flash[:error] = t("flash.collaborators.wrong_user", uname: params[:user_uname]) - elsif parent.add_member(@user, params[:role]) + elsif @group.add_member(@user, params[:role]) flash[:notice] = t("flash.members.successfully_added") else flash[:error] = t("flash.members.error_in_adding") end - redirect_to group_members_path(parent) + redirect_to group_members_path(@group) end end diff --git a/app/views/groups/members/index.html.haml b/app/views/groups/members/index.html.haml index c01b4bc47..f233369aa 100644 --- a/app/views/groups/members/index.html.haml +++ b/app/views/groups/members/index.html.haml @@ -9,7 +9,7 @@ %th= t("layout.collaborators.members") %th{colspan: "3"}= t("layout.collaborators.roles") %tbody - - (parent.members - [parent.owner]).each do |user| + - (@group.members - [@group.owner]).each do |user| %tr %td %span#niceCheckbox1.niceCheck-main= check_box_tag "user_remove[#{user.id}][]" @@ -18,13 +18,13 @@ .forimg= link_to user.fullname, user_path(user) - Relation::ROLES.each_with_index do |role, i| %td - .radio= radio_button_tag "user[#{user.id}]", role, ((parent.actors.exists? actor_id: user.id, actor_type: 'User', role: role) ? :checked : nil), class: 'niceRadio' + .radio= radio_button_tag "user[#{user.id}]", role, ((@group.actors.exists? actor_id: user.id, actor_type: 'User', role: role) ? :checked : nil), class: 'niceRadio' .forradio= t("layout.collaborators.role_names.#{ role }") = link_to_function t("layout.delete"), "deleteAdminMember();", class: 'button' .both .hr.top -= form_tag add_group_members_path(parent) do += form_tag add_group_members_path(@group) do .admin-search= autocomplete_field_tag 'user_uname', params[:user_uname], autocomplete_user_uname_autocompletes_path .admin-role .lineForm= select_tag 'role', options_for_collaborators_roles_select diff --git a/lib/plugins/related_models/base.rb b/lib/plugins/related_models/base.rb deleted file mode 100644 index c00c2e077..000000000 --- a/lib/plugins/related_models/base.rb +++ /dev/null @@ -1,23 +0,0 @@ -module RelatedModels - class Base < ::ApplicationController - def self.is_child!(base) - base.class_eval do -# include InheritedResources::Actions -# include InheritedResources::BaseHelpers - extend RelatedModels::ClassMethods - extend RelatedModels::UrlHelpers - - helper_method :parent_url, :parent_path - - self.class_attribute :parents_symbols, :resources_configuration, instance_writer: false - - self.parents_symbols ||= [] - self.resources_configuration ||= {} - - protected :parents_symbols, :resources_configuration, :parents_symbols?, :resources_configuration? - end - end - - is_child!(self) - end -end diff --git a/lib/plugins/related_models/belongs_to_helpers.rb b/lib/plugins/related_models/belongs_to_helpers.rb deleted file mode 100644 index 713306353..000000000 --- a/lib/plugins/related_models/belongs_to_helpers.rb +++ /dev/null @@ -1,39 +0,0 @@ -module RelatedModels - module BelongsToHelpers - protected - def parent? - true - end - - def parent - @parent ||= find_parent - end - - def parent_type - parent.class.name.underscore.to_sym - end - - private - - def symbols_for_association_chain - parents_symbols.compact - end - - def find_parent - k = params.symbolize_keys.keys - res = nil - - symbols_for_association_chain.reverse.each do |sym| - if k.include? resources_configuration[sym][:param] - parent_config = resources_configuration[sym] - res = parent_config[:parent_class].send(parent_config[:finder], params[parent_config[:param]]) - break - end - end - unless res - raise "Couldn't find parent" - end - return res - end - end -end diff --git a/lib/plugins/related_models/class_methods.rb b/lib/plugins/related_models/class_methods.rb deleted file mode 100644 index 0a912a597..000000000 --- a/lib/plugins/related_models/class_methods.rb +++ /dev/null @@ -1,68 +0,0 @@ -module RelatedModels - module ClassMethods - protected - def belongs_to(*symbols) - options = symbols.extract_options! - - options.symbolize_keys! - options.assert_valid_keys(:polymorphic, :optional, :finder) - - optional = options.delete(:optional) - polymorphic = options.delete(:polymorphic) - finder = options.delete(:finder) - - include BelongsToHelpers if self.parents_symbols.empty? - - acts_as_polymorphic! if polymorphic || optional - - raise ArgumentError, 'You have to give me at least one association name.' if symbols.empty? - raise ArgumentError, 'You cannot define multiple associations with options: #{options.keys.inspect} to belongs to.' unless symbols.size == 1 || options.empty? - - symbols.each do |symbol| - symbol = symbol.to_sym - - if polymorphic || optional - self.parents_symbols << :polymorphic unless self.parents_symbols.include?(:polymorphic) - self.resources_configuration[:polymorphic] ||= {} - self.resources_configuration[:polymorphic][:symbols] ||= [] - - self.resources_configuration[:polymorphic][:symbols] << symbol - self.resources_configuration[:polymorphic][:optional] ||= optional - else - self.parents_symbols << symbol - end - - config = self.resources_configuration[symbol] = {} - - config[:parent_class] = begin - class_name = symbol.to_s.pluralize.classify - class_name.constantize - rescue NameError => e - raise unless e.message.include?(class_name) - nil - end - - config[:collection_name] = symbol.to_s.pluralize.to_sym - config[:instance_name] = symbol - config[:param] = :"#{symbol}_id" - config[:route_name] = symbol - config[:finder] = finder || :find - end - - create_resources_url_helpers! - helper_method :parent, :parent? - end - - private - def acts_as_polymorphic! #:nodoc: - unless self.parents_symbols.include?(:polymorphic) - include PolymorphicHelpers - helper_method :parent_type, :parent_class - end - end - - def inherited(base) - super(base) - end - end -end diff --git a/lib/plugins/related_models/polymorphic_helpers.rb b/lib/plugins/related_models/polymorphic_helpers.rb deleted file mode 100644 index dd604b6c4..000000000 --- a/lib/plugins/related_models/polymorphic_helpers.rb +++ /dev/null @@ -1,80 +0,0 @@ -module RelatedModels - module PolymorphicHelpers - - protected - - # Returns the parent type. A Comments class can have :task, :file, :note - # as parent types. - # - def parent_type - @parent_type - end - - def parent_class - parent.class if @parent_type - end - - # Returns the parent object. They are also available with the instance - # variable name: @task, @file, @note... - # - def parent - k = params.symbolize_keys.keys - res = nil - - symbols_for_association_chain.reverse.each do |sym| - if k.include? resources_configuration[sym][:param] - parent_config = resources_configuration[sym] - res = parent_config[:parent_class].send(parent_config[:finder], params[parent_config[:param]]) - break - end - end - return res - end - - # If the polymorphic association is optional, we might not have a parent. - # - def parent? - if resources_configuration[:polymorphic][:optional] - parents_symbols.size > 1 || !@parent_type.nil? - else - true - end - end - - private - - # Maps parents_symbols to build association chain. - # - # If the parents_symbols find :polymorphic, it goes through the - # params keys to see which polymorphic parent matches the given params. - # - # When optional is given, it does not raise errors if the polymorphic - # params are missing. - # - def symbols_for_association_chain #:nodoc: - polymorphic_config = resources_configuration[:polymorphic] - parents_symbols.map do |symbol| - if symbol == :polymorphic - params_keys = params.keys - - keys = polymorphic_config[:symbols].map do |poly| - params_keys.include?(resources_configuration[poly][:param].to_s) ? poly : nil - end.compact - - if keys.empty? - raise ScriptError, "Could not find param for polymorphic association. The request" << - "parameters are #{params.keys.inspect} and the polymorphic " << - "associations are #{polymorphic_config[:symbols].inspect}." unless polymorphic_config[:optional] - - nil - else - @parent_type = keys[-1].to_sym - @parent_types = keys.map(&:to_sym) - end - else - symbol - end - end.flatten.compact - end - end -end diff --git a/lib/plugins/related_models/url_helpers.rb b/lib/plugins/related_models/url_helpers.rb deleted file mode 100644 index 031e2068e..000000000 --- a/lib/plugins/related_models/url_helpers.rb +++ /dev/null @@ -1,28 +0,0 @@ -module RelatedModels - module UrlHelpers - protected - - def create_resources_url_helpers! - segment = if parents_symbols.include? :polymorphic - :polymorphic - else - resources_configuration[symbols_for_association_chain.first][:route_name] - end - - unless parent.nil? - class_eval <<-URL_HELPERS, __FILE__, __LINE__ - protected - def parent_path(*given_args) - given_options = given_args.extract_options! - #{segment}_path(parent, given_options) - end - - def parent_url(*given_args) - given_options = given_args.extract_options! - #{segment}_url(parent, given_options) - end - URL_HELPERS - end - end - end -end From 2e8eb6df79aee8324c7a90181884b1d8096c0380 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 5 Mar 2014 15:15:15 +0600 Subject: [PATCH 29/34] [#247] remove unneeded file --- lib/plugins/related_models.rb | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 lib/plugins/related_models.rb diff --git a/lib/plugins/related_models.rb b/lib/plugins/related_models.rb deleted file mode 100644 index 00e615e06..000000000 --- a/lib/plugins/related_models.rb +++ /dev/null @@ -1,16 +0,0 @@ -module RelatedModels - extend ActiveSupport::Autoload - - autoload :ClassMethods - autoload :BelongsToHelpers - autoload :PolymorphicHelpers - autoload :UrlHelpers - autoload :Base -end - -class ActionController::Base - #include ClassMethods - def self.is_related_controller! - RelatedModels::Base.is_child!(self) - end -end From bd4f7fbe4de291e34e986df4c38f5eae17b3646f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 6 Mar 2014 01:44:37 +0400 Subject: [PATCH 30/34] updated build_list status transactions --- app/models/build_list.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 78976b241..c64cfd968 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -231,12 +231,12 @@ class BuildList < ActiveRecord::Base # ===== into testing - end event :build_success do - transition [:build_started, :build_canceled] => :success + transition [:build_started, :build_canceling, :build_canceled] => :success end [:build_error, :tests_failed].each do |kind| event kind do - transition [:build_started, :build_canceling] => kind + transition [:build_started, :build_canceling, :build_canceled] => kind end end From 8f75f1b0770e211fd2816f9c71c0cc8beb7dc6cb Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 6 Mar 2014 02:18:19 +0400 Subject: [PATCH 31/34] updated response for live inspector --- app/controllers/api/v1/jobs_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index 03484dc5d..5b1ffb057 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -57,7 +57,10 @@ class Api::V1::JobsController < Api::V1::BaseController end def status - render text: Resque.redis.get(params[:key]) + if params[:key] =~ /\Aabfworker::(rpm|iso)-worker-[\d]+::live-inspector\z/ + status = Resque.redis.get(params[:key]) + end + render json: { status: status }.to_json end def logs From 636ae022bfe8c17c0ea1082f104ccd274b757589 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 6 Mar 2014 17:24:33 +0600 Subject: [PATCH 32/34] [#247] remove private users --- .../platforms/private_users_controller.rb | 31 ------------ .../platforms/privates_controller.rb | 32 ------------ app/models/ability.rb | 3 -- app/models/event_log_observer.rb | 2 +- app/models/private_user.rb | 32 ------------ app/views/platforms/base/_sidebar.html.haml | 3 -- .../platforms/private_users/index.html.haml | 50 ------------------- config/locales/en.yml | 16 ------ config/locales/models/event_log.en.yml | 4 -- config/locales/models/event_log.ru.yml | 4 -- config/locales/models/platform.en.yml | 1 - config/locales/models/platform.ru.yml | 1 - config/locales/ru.yml | 16 ------ config/routes.rb | 2 - .../20140306102620_destroy_private_user.rb | 15 ++++++ db/schema.rb | 13 +---- .../private_users_controller_spec.rb | 5 -- .../platforms/privates_controller_spec.rb | 5 -- spec/factories/private_users.rb | 8 --- spec/models/cancan_spec.rb | 15 ------ spec/models/private_user_spec.rb | 5 -- 21 files changed, 18 insertions(+), 245 deletions(-) delete mode 100644 app/controllers/platforms/private_users_controller.rb delete mode 100644 app/controllers/platforms/privates_controller.rb delete mode 100644 app/models/private_user.rb delete mode 100644 app/views/platforms/private_users/index.html.haml create mode 100644 db/migrate/20140306102620_destroy_private_user.rb delete mode 100644 spec/controllers/platforms/private_users_controller_spec.rb delete mode 100644 spec/controllers/platforms/privates_controller_spec.rb delete mode 100644 spec/factories/private_users.rb delete mode 100644 spec/models/private_user_spec.rb diff --git a/app/controllers/platforms/private_users_controller.rb b/app/controllers/platforms/private_users_controller.rb deleted file mode 100644 index b36163cbb..000000000 --- a/app/controllers/platforms/private_users_controller.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Platforms::PrivateUsersController < Platforms::BaseController - before_filter :authenticate_user! - before_filter :find_platform_and_private_users - - load_and_authorize_resource :platform - - def index - end - - def create - old_pair = PrivateUser.find_by_platform_id_and_user_id(params[:platform_id], current_user.id) - old_pair.destroy if old_pair - - @pair = PrivateUser.generate_pair(params[:platform_id], current_user.id) - @urpmi_list = @platform.urpmi_list(request.host, @pair) - redirect_to platform_private_users_path(params[:platform_id]), notice: I18n.t('flash.private_users', login: @pair[:login], password: @pair[:pass]) - end - - #def destroy - # user = PrivateUser.find(params[:id]) - # user.destroy - # redirect_to platform_private_users_path(params[:platform_id]) - #end - - protected - - def find_platform_and_private_users - @private_users = PrivateUser.where(platform_id: params[:platform_id]).paginate page: params[:page] - @platform = Platform.find(params[:platform_id]) - end -end diff --git a/app/controllers/platforms/privates_controller.rb b/app/controllers/platforms/privates_controller.rb deleted file mode 100644 index f1c129dca..000000000 --- a/app/controllers/platforms/privates_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -class Platforms::PrivatesController < Platforms::BaseController - require 'digest/sha2' - - before_filter :find_platform - before_filter :authenticate - - def show - file_name = "#{APP_CONFIG['root_path']}/platforms/#{params[:platform_name]}/#{params[:file_path]}" - - if File.directory?(file_name) || !File.exists?(file_name) - render file: "#{Rails.root}/public/404.html", layout: false, status: 404 - else - send_file file_name - end - end - - protected - - def authenticate - authenticate_or_request_with_http_basic do |username, password| - PrivateUser.exists?( - login: username, - password: Digest::SHA2.new.hexdigest(password), - platform_id: @platform.try(:id) - ) - end - end - - def find_platform - @platform = Platform.find_by_name(params[:platform_name]) - end -end diff --git a/app/models/ability.rb b/app/models/ability.rb index f7e22d199..e64376893 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -140,9 +140,6 @@ class Ability can([:create, :cancel, :update], ProductBuildList) {|pbl| can?(:update, pbl.product)} can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} - can [:read, :create], PrivateUser, platform: {owner_type: 'User', owner_id: user.id} - can [:read, :create], PrivateUser, platform: {owner_type: 'Group', owner_id: user_group_ids} - can :read, Issue, project: {owner_type: 'User', owner_id: user.id} can :read, Issue, project: {owner_type: 'Group', owner_id: user_group_ids} can(:read, Issue, read_relations_for('issues', 'projects')) {|issue| can? :read, issue.project rescue nil} diff --git a/app/models/event_log_observer.rb b/app/models/event_log_observer.rb index 4258cd445..df47381c3 100644 --- a/app/models/event_log_observer.rb +++ b/app/models/event_log_observer.rb @@ -1,5 +1,5 @@ class EventLogObserver < ActiveRecord::Observer - observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list + observe :user, :platform, :repository, :project, :product, :build_list, :product_build_list def after_create(record) ActiveSupport::Notifications.instrument("event_log.observer", eventable: record) diff --git a/app/models/private_user.rb b/app/models/private_user.rb deleted file mode 100644 index 53413a17d..000000000 --- a/app/models/private_user.rb +++ /dev/null @@ -1,32 +0,0 @@ -class PrivateUser < ActiveRecord::Base - require 'digest/sha2' - - belongs_to :platform - belongs_to :user - - validate :login, uniqueness: true - - def event_log_message - {platform: platform.name, user: user.uname}.inspect - end - - class << self - def can_generate_more?(user_id, platform_id) - !PrivateUser.exists?(user_id: user_id, platform_id: platform_id) - end - - def generate_pair(platform_id, user_id) - login = "login_#{ActiveSupport::SecureRandom.hex(16)}" - pass = "pass_#{ActiveSupport::SecureRandom.hex(16)}" - - PrivateUser.create( - login: login, - password: Digest::SHA2.new.hexdigest(pass), - platform_id: platform_id, - user_id: user_id - ) - - {login: login, pass: pass} - end - end -end diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index 99818f383..567493589 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -34,6 +34,3 @@ = link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform) %li{class: (contr == :tokens) ? 'active' : ''} = link_to t('layout.tokens.header'), platform_tokens_path(@platform) - -#- if current_user.owner_of? @platform or current_user.admin? - %li{class: (act == :index && contr == :private_users) ? 'active' : ''} - = link_to t("layout.platforms.private_users"), platform_private_users_path(@platform) diff --git a/app/views/platforms/private_users/index.html.haml b/app/views/platforms/private_users/index.html.haml deleted file mode 100644 index ad70e003a..000000000 --- a/app/views/platforms/private_users/index.html.haml +++ /dev/null @@ -1,50 +0,0 @@ --set_meta_tags title: [title_object(current_user.repository), t('layout.personal_repositories.private_users')] -.block - .secondary-navigation - %ul.wat-cf - %li.first= link_to t("layout.personal_repositories.show"), personal_repository_path(current_user.personal_repository) - %li= link_to t("layout.personal_repositories.settings"), settings_personal_repository_path(current_user.personal_repository) - %li.active= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(current_user.personal_platform) if current_user.personal_platform.hidden? - .content - .inner - %p - %b - = t("activerecord.attributes.platform.name") - \: - = @platform.name - %p - %b - = t("activerecord.attributes.repository.platform") - \: - = link_to @platform.name, platform_path(@platform) - - - if @urpmi_list - = render 'shared/urpmi_list', urpmi_commands: @urpmi_list - .wat-cf - =# link_to image_tag("x.png", alt: t("layout.delete")) + " " + t("layout.delete"), platform_repository_path(@platform, @repository), method: "delete", class: "button", confirm: t("layout.repositories.confirm_delete") - %br - .inner - =t('layout.private_users.warning_message') - -.block - .secondary-navigation - %ul.wat-cf - %li.first.active= link_to t("layout.private_users.list"), platform_private_users_path(@platform) - %li= link_to t("layout.private_users.new"), platform_private_users_path(@platform), method: :post if PrivateUser.can_generate_more?(current_user.id, @platform.id) - .content - %h2.title - = t("layout.private_users.list_header") - .inner - %table.table - %tr - %th.first= t("activerecord.attributes.private_user.login") - %th.last   - - @private_users.each do |private_user| - %tr{class: cycle("odd", "even")} - %td - = private_user.login - %td.last - #{link_to t("layout.private_users.regenerate_btn"), platform_private_users_path(@platform), method: :post, confirm: t("layout.private_users.confirm_regenerate")} - .actions-bar.wat-cf - .actions - = will_paginate @private_users \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 246f0a180..91e572fde 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -91,15 +91,6 @@ en: sign_in_header: Sign in sign_up_with: or sign in with - private_users: - list: List - new: New pair - list_header: Pair login/password - confirm_delete: Are you sure to delete this pair login/password? - confirm_regenerate: Are you sure to regenerate this pair login/password? - regenerate_btn: Regenerate - warning_message: Warning - Old data set as invalid when new data obtaining - collaborators: back_to_proj: Back to project edit: Edit list @@ -132,8 +123,6 @@ en: saved: Settings saved success save_error: Setting update error - private_users: "Login: %{login} Password: %{password}" - subscribe: saved: Subscription on notifications for this task is created saved_error: Subscription create error @@ -177,7 +166,6 @@ en: can_have_less_or_equal: You cannot have more than %{count} projects. models: - private_user: Private user product_build_list: Product build list attributes: @@ -195,10 +183,6 @@ en: new_build: Notify about my build tasks new_associated_build: Notify about associated with me build tasks - private_user: - login: Login - password: Password - arch: name: Name created_at: Created diff --git a/config/locales/models/event_log.en.yml b/config/locales/models/event_log.en.yml index b44100e0e..aca5e3f67 100644 --- a/config/locales/models/event_log.en.yml +++ b/config/locales/models/event_log.en.yml @@ -11,7 +11,6 @@ en: 'devise/sessions_controller': 'User Authentication' 'devise/passwords_controller': 'Password recovery' 'users/omniauth_callbacks_controller': 'External users authentication' - private_users_controller: 'access to private repositories' personal_repositories_controller: 'Personal repositories management' actions: 'devise/sessions_controller': @@ -27,9 +26,6 @@ en: create: 'sent to build' rpc_controller: xe_index: inquiry - private_users_controller: - create: 'given' - destroy: 'deleted' personal_repositories_controller: change_visibility: 'status change' create: 'created' diff --git a/config/locales/models/event_log.ru.yml b/config/locales/models/event_log.ru.yml index 8d4458cdc..d979d9f95 100644 --- a/config/locales/models/event_log.ru.yml +++ b/config/locales/models/event_log.ru.yml @@ -11,7 +11,6 @@ ru: 'devise/sessions_controller': 'Аутентификация пользователей' 'devise/passwords_controller': 'Восстановление пароля' 'users/omniauth_callbacks_controller': 'Внешняя аутентификация пользователей' - private_users_controller: 'Доступ к приватным репозиториям' personal_repositories_controller: 'Управление персональными репозиториями' actions: 'devise/sessions_controller': @@ -27,9 +26,6 @@ ru: create: 'отправлен на сборку' rpc_controller: xe_index: запрос - private_users_controller: - create: 'предоставлен' - destroy: 'удален' personal_repositories_controller: change_visibility: 'смена статуса' create: 'создано' diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index e59d5bc29..ebc845cb9 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -35,7 +35,6 @@ en: visibility: Visibility platform_type: Platform type distrib_type: Distribution type - private_users: Access data confirm_clone: Clone? clone: Clone delete_warning: Attention! Deleted platform can not be restored! diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index cea910b36..a3b38a16d 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -35,7 +35,6 @@ ru: visibility: Видимость platform_type: Тип платформы distrib_type: Тип дистрибутива - private_users: Данные для доступа confirm_clone: Клонировать? clone: Клонировать delete_warning: Внимание! Удаленная платформа восстановлению не подлежит. diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 7bf16e90a..eb2874fba 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -91,15 +91,6 @@ ru: sign_in_header: Вход в систему sign_up_with: или войти с помощью - private_users: - list: Список - new: Новая пара - list_header: Пары логин/пароль - confirm_delete: Вы уверены, что хотите удалить эту пару логин/пароль? - confirm_regenerate: Вы уверены, что хотите перегенерировать эту пару логин/пароль? - regenerate_btn: Перегенерировать - warning_message: Примечание - При получении новых данных старые становятся недействительными - collaborators: back_to_proj: Вернуться к проекту edit: Редактировать список @@ -132,8 +123,6 @@ ru: saved: Настройки успешно сохранены save_error: При обновлении настроек произошла ошибка - private_users: "Логин: %{login} Пароль: %{password}" - subscribe: saved: Вы подписаны на оповещения для этой задачи saved_error: При создании подписки произошла ошибка @@ -177,7 +166,6 @@ ru: can_have_less_or_equal: Нельзя иметь больше, чем %{count} проектов. models: - private_user: Приватный пользователь product_build_list: Сборочный лист продукта attributes: @@ -195,10 +183,6 @@ ru: new_build: Оповещать о моих сборочных заданиях new_associated_build: Оповещать о связанных со мной сборочных заданиях - private_user: - login: Логин - password: Пароль - arch: name: Название created_at: Создана diff --git a/config/routes.rb b/config/routes.rb index c12a6e131..6b4369d0d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -165,7 +165,6 @@ Rosa::Application.routes.draw do scope module: 'platforms' do resources :platforms, constraints: {id: Platform::NAME_PATTERN} do - resources :private_users, except: [:show, :destroy, :update] member do put :regenerate_metadata put :clear @@ -221,7 +220,6 @@ Rosa::Application.routes.draw do end resources :maintainers, only: [:index] end - match '/private/:platform_name/*file_path' => 'privates#show' resources :product_build_lists, only: [:index, :show] end diff --git a/db/migrate/20140306102620_destroy_private_user.rb b/db/migrate/20140306102620_destroy_private_user.rb new file mode 100644 index 000000000..0e57648f1 --- /dev/null +++ b/db/migrate/20140306102620_destroy_private_user.rb @@ -0,0 +1,15 @@ +class DestroyPrivateUser < ActiveRecord::Migration + def self.up + drop_table :private_users + end + + def self.down + create_table :private_users do |t| + t.integer :platform_id + t.string :login + t.string :password + t.integer :user_id + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9cb057529..b21cff4f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140224134012) do +ActiveRecord::Schema.define(:version => 20140306102620) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -285,7 +285,6 @@ ActiveRecord::Schema.define(:version => 20140224134012) do t.string "arch_names" t.integer "user_id" t.boolean "auto_publish", :default => false, :null => false - t.integer "build_lists_count", :default => 0, :null => false t.boolean "stop_build", :default => false, :null => false t.text "projects_list" t.integer "missed_projects_count", :default => 0, :null => false @@ -295,6 +294,7 @@ ActiveRecord::Schema.define(:version => 20140224134012) do t.text "extra_repositories" t.text "extra_build_lists" t.boolean "increase_release_tag", :default => false, :null => false + t.integer "build_lists_count", :default => 0 end create_table "platform_arch_settings", :force => true do |t| @@ -329,15 +329,6 @@ ActiveRecord::Schema.define(:version => 20140224134012) do add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false - create_table "private_users", :force => true do |t| - t.integer "platform_id" - t.string "login" - t.string "password" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "user_id" - end - create_table "product_build_lists", :force => true do |t| t.integer "product_id" t.integer "status", :null => false diff --git a/spec/controllers/platforms/private_users_controller_spec.rb b/spec/controllers/platforms/private_users_controller_spec.rb deleted file mode 100644 index 6173681d8..000000000 --- a/spec/controllers/platforms/private_users_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Platforms::PrivateUsersController do - -end diff --git a/spec/controllers/platforms/privates_controller_spec.rb b/spec/controllers/platforms/privates_controller_spec.rb deleted file mode 100644 index 5a8c7bd99..000000000 --- a/spec/controllers/platforms/privates_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Platforms::PrivatesController do - -end diff --git a/spec/factories/private_users.rb b/spec/factories/private_users.rb deleted file mode 100644 index e761d80ab..000000000 --- a/spec/factories/private_users.rb +++ /dev/null @@ -1,8 +0,0 @@ -FactoryGirl.define do - factory :private_user do - login { FactoryGirl.generate(:string) } - password { FactoryGirl.generate(:string) } - association :platform, factory: :platform - association :user, factory: :user - end -end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index f10dcc8f4..c3e0f56f3 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -130,21 +130,6 @@ describe CanCan do @ability.should_not be_able_to(:manage, RegisterRequest) end - context "private users relations" do - before(:each) do - @private_user = FactoryGirl.create(:private_user) - - @private_user.platform.owner = @user - @private_user.platform.save - end - - [:read, :create].each do |action| - it "should be able to #{ action } PrivateUser" do - @ability.should be_able_to(action, @private_user) - end - end - end - context 'as project collaborator' do before(:each) do @project = FactoryGirl.create(:project_with_commit) diff --git a/spec/models/private_user_spec.rb b/spec/models/private_user_spec.rb deleted file mode 100644 index afbac1006..000000000 --- a/spec/models/private_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe PrivateUser do - pending "add some examples to (or delete) #{__FILE__}" -end From 2e4112e6a4c8d12159cbb5e1c94bffafb90be862 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 6 Mar 2014 21:45:33 +0600 Subject: [PATCH 33/34] Add skype notifications --- Gemfile | 2 ++ Gemfile.lock | 4 +++ config/deploy.rb.sample | 3 ++ lib/recipes/skype.rb | 80 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 lib/recipes/skype.rb diff --git a/Gemfile b/Gemfile index 29f1b5617..de2fed797 100644 --- a/Gemfile +++ b/Gemfile @@ -112,6 +112,8 @@ group :development do gem 'binding_of_caller' gem 'meta_request' gem 'localeapp' + gem 'skype' + gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index a186dc444..9418d22cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -411,6 +411,8 @@ GEM skinny (0.2.3) eventmachine (~> 1.0.0) thin (~> 1.5.0) + skype (0.2.7) + tmp_cache soundmanager-rails (1.0.0) sprockets (2.2.2) hike (~> 1.2) @@ -433,6 +435,7 @@ GEM time_diff (0.3.0) activesupport i18n + tmp_cache (0.1.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) @@ -540,6 +543,7 @@ DEPENDENCIES sass-rails (~> 3.2.5) shotgun shoulda + skype soundmanager-rails state_machine therubyracer (~> 0.12.1) diff --git a/config/deploy.rb.sample b/config/deploy.rb.sample index f2e416ea5..66d98e9b2 100644 --- a/config/deploy.rb.sample +++ b/config/deploy.rb.sample @@ -33,6 +33,9 @@ require 'puma/capistrano' set :workers_count, 4 require './lib/recipes/resque' +require './lib/recipes/skype' +set :skype_topic, 'ABF' # Skype chat topic name + namespace :deploy do task :symlink_all, :roles => :app do run "mkdir -p #{fetch :shared_path}/config" diff --git a/lib/recipes/skype.rb b/lib/recipes/skype.rb new file mode 100644 index 000000000..c8070ba15 --- /dev/null +++ b/lib/recipes/skype.rb @@ -0,0 +1,80 @@ +require 'skype' + +Capistrano::Configuration.instance(:must_exist).load do + Skype.config app_name: 'test-message' + set :skype_send_notification, true + + namespace :skype do + task :trigger_notification do + set :skype_send_notification, true if !dry_run + end + + task :configure_for_migrations do + set :skype_with_migrations, ' (with migrations)' + end + + task :notify_deploy_started do + if skype_send_notification + + environment_string = env + if self.respond_to?(:stage) + environment_string = "#{stage} (#{env})" + end + + on_rollback do + send("Cancelled deployment of #{deployment_name} to #{environment_string}.") + send('#'*60) + end + send('#'*60) + send("Deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") + end + end + + task :notify_deploy_finished do + if skype_send_notification + + environment_string = env + if self.respond_to?(:stage) + environment_string = "#{stage} (#{env})" + end + + send("Finished deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") + send('#'*60) + end + end + + def send(message) + set :skype_client, Skype.chats.find { |c| c.topic == fetch(:skype_topic, '') } if fetch(:skype_client, nil).nil? + + begin + skype_client.post(message) + rescue => e + puts e.message + puts e.backtrace + end + end + + def deployment_name + if fetch(:branch, nil) + name = "#{application}/#{branch}" + name += " (revision #{real_revision[0..7]})" if real_revision + name + else + application + end + end + + def message_notification + fetch(:skype_announce, false) + end + + def env + fetch(:skype_env, fetch(:rack_env, fetch(:rails_env, "production"))) + end + end + + before "deploy", "skype:trigger_notification" + before "deploy:update_code", "skype:notify_deploy_started" + after "deploy", "skype:notify_deploy_finished" + after "deploy:migrations", "skype:notify_deploy_finished" +end From 31edf3e57ca9371190b6b55a5a771bb2e3803ca8 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 6 Mar 2014 21:50:58 +0600 Subject: [PATCH 34/34] small refactoring the skype recipe --- lib/recipes/skype.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/recipes/skype.rb b/lib/recipes/skype.rb index c8070ba15..c73c9b5d9 100644 --- a/lib/recipes/skype.rb +++ b/lib/recipes/skype.rb @@ -22,11 +22,9 @@ Capistrano::Configuration.instance(:must_exist).load do end on_rollback do - send("Cancelled deployment of #{deployment_name} to #{environment_string}.") - send('#'*60) + send("Cancelled deployment of #{deployment_name} to #{environment_string}.\n#{'#'*60}") end - send('#'*60) - send("Deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") + send("#{'#'*60}\nDeploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") end end @@ -38,8 +36,7 @@ Capistrano::Configuration.instance(:must_exist).load do environment_string = "#{stage} (#{env})" end - send("Finished deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") - send('#'*60) + send("Finished deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.\n#{'#'*60}") end end