Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactoring

  • Loading branch information...
commit 8d178b856f5e1ebe2c93e1e9bdc3eb113194398a 1 parent f1323bf
@avokhmin avokhmin authored
Showing with 13 additions and 16 deletions.
  1. +2 −6 app/models/build_list.rb
  2. +11 −10 lib/abf_worker/model_helper.rb
View
8 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 @@ def self.next_build
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
View
21 lib/abf_worker/model_helper.rb
@@ -39,7 +39,6 @@ def add_job_to_abf_worker_queue
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 @@ def worker_queue_class
"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
Please sign in to comment.
Something went wrong with that request. Please try again.