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'