Fixed: cleaning of old queues

This commit is contained in:
Vokhmin Alexey V 2014-02-27 23:25:37 +04:00
parent 4bde41588a
commit 5b15444543
2 changed files with 13 additions and 8 deletions

View File

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

View File

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