BUGFIX: recovery code in case an unknown job is scheduled

This commit is contained in:
Sam 2014-03-04 07:36:50 +11:00
parent a05606d1ff
commit 5c3f2feed4
2 changed files with 12 additions and 1 deletions

View file

@ -184,7 +184,11 @@ module Scheduler
return unless key
if due.to_i <= Time.now.to_i
klass = get_klass(key)
return unless klass
unless klass
# corrupt key, nuke it (renamed job or something)
redis.zrem Manager.queue_key, key
return
end
info = schedule_info(klass)
info.prev_run = Time.now.to_i
info.prev_result = "QUEUED"

View file

@ -59,6 +59,13 @@ describe Scheduler::Manager do
describe '#tick' do
it 'should nuke missing jobs' do
$redis.zadd Scheduler::Manager.queue_key, Time.now.to_i - 1000, "BLABLA"
manager.tick
$redis.zcard(Scheduler::Manager.queue_key).should == 0
end
it 'should recover from crashed manager' do
info = manager.schedule_info(Testing::SuperLongJob)