From f1323bf9bd42b2f4b82469734de6298d495d38bc Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 21 Feb 2014 22:20:05 +0400 Subject: [PATCH] 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