Clean/restore queues

This commit is contained in:
Vokhmin Alexey V 2014-02-21 22:20:05 +04:00
parent 5f5ed0d1ce
commit f1323bf9bd
2 changed files with 10 additions and 9 deletions

View File

@ -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

View File

@ -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