Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
don't crash if there's an exception while enqueueing a job
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Grijalva authored and bvandenbos committed Jan 14, 2011
1 parent 974ceec commit e72a4a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/resque/scheduler.rb
Expand Up @@ -103,14 +103,18 @@ def enqueue_delayed_items_for_timestamp(timestamp)
begin
handle_shutdown do
if item = Resque.next_item_for_timestamp(timestamp)
log "queuing #{item['class']} [delayed]"
queue = item['queue'] || Resque.queue_from_class(constantize(item['class']))
# Support custom job classes like job with status
if (job_klass = item['custom_job_class']) && (job_klass != 'Resque::Job')
# custom job classes not supporting the same API calls must implement the #schedule method
constantize(job_klass).scheduled(queue, item['class'], *item['args'])
else
Resque::Job.create(queue, item['class'], *item['args'])
begin
log "queuing #{item['class']} [delayed]"
queue = item['queue'] || Resque.queue_from_class(constantize(item['class']))
# Support custom job classes like job with status
if (job_klass = item['custom_job_class']) && (job_klass != 'Resque::Job')
# custom job classes not supporting the same API calls must implement the #schedule method
constantize(job_klass).scheduled(queue, item['class'], *item['args'])
else
Resque::Job.create(queue, item['class'], *item['args'])
end
rescue
log! "Failed to enqueue #{klass_name}:\n #{$!}"
end
end
end
Expand All @@ -137,6 +141,8 @@ def enqueue_from_config(config)
else
Resque::Job.create(queue, klass_name, *params)
end
rescue
log! "Failed to enqueue #{klass_name}:\n #{$!}"
end

def rufus_scheduler
Expand Down
5 changes: 5 additions & 0 deletions test/scheduler_test.rb
Expand Up @@ -20,6 +20,11 @@ def test_enqueue_from_config_with_every_syntax
Resque::Scheduler.enqueue_from_config('every' => '1m', 'class' => 'JamesJob', 'args' => '/tmp', 'queue' => 'james_queue')
end

def test_enqueue_from_config_doesnt_crash_on_exception_when_enqueueing
Resque::Job.stubs(:create).raises(Resque::NoQueueError, 'test exception').with(:ivar, 'SomeIvarJob', '/tmp')
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
end

def test_enqueue_from_config_puts_stuff_in_the_resque_queue
Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
Expand Down

0 comments on commit e72a4a4

Please sign in to comment.