diff --git a/lib/resque/scheduler.rb b/lib/resque/scheduler.rb index e6c3571b..3022d001 100644 --- a/lib/resque/scheduler.rb +++ b/lib/resque/scheduler.rb @@ -113,13 +113,14 @@ def enqueue_delayed_items_for_timestamp(timestamp) 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'])) + klass = constantize(item['class']) + queue = item['queue'] || Resque.queue_from_class(klass) # 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']) + Resque::Job.create(queue, klass, *item['args']) end end end @@ -137,14 +138,15 @@ def handle_shutdown def enqueue_from_config(config) args = config['args'] || config[:args] klass_name = config['class'] || config[:class] + klass = constantize(klass_name) params = args.nil? ? [] : Array(args) - queue = config['queue'] || config[:queue] || Resque.queue_from_class(constantize(klass_name)) + queue = config['queue'] || config[:queue] || Resque.queue_from_class(klass) # Support custom job classes like job with status if (job_klass = config['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, klass_name, *params) else - Resque::Job.create(queue, klass_name, *params) + Resque::Job.create(queue, klass, *params) end end diff --git a/test/delayed_queue_test.rb b/test/delayed_queue_test.rb index 9498ba22..67fea918 100644 --- a/test/delayed_queue_test.rb +++ b/test/delayed_queue_test.rb @@ -116,7 +116,7 @@ def test_handle_delayed_items_with_items Resque.enqueue_at(t, SomeIvarJob) # 2 SomeIvarJob jobs should be created in the "ivar" queue - Resque::Job.expects(:create).twice.with('ivar', 'SomeIvarJob', nil) + Resque::Job.expects(:create).twice.with('ivar', SomeIvarJob, nil) Resque.expects(:queue_from_class).never # Should NOT need to load the class Resque::Scheduler.handle_delayed_items end @@ -128,7 +128,7 @@ def test_enqueue_delayed_items_for_timestamp Resque.enqueue_at(t, SomeIvarJob) # 2 SomeIvarJob jobs should be created in the "ivar" queue - Resque::Job.expects(:create).twice.with('ivar', 'SomeIvarJob', nil) + Resque::Job.expects(:create).twice.with('ivar', SomeIvarJob, nil) Resque.expects(:queue_from_class).never # Should NOT need to load the class Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) @@ -144,7 +144,7 @@ def test_works_with_out_specifying_queue__upgrade_case # Since we didn't specify :queue when calling delayed_push, it will be forced # to load the class to figure out the queue. This is the upgrade case from 1.0.4 # to 1.0.5. - Resque::Job.expects(:create).once.with(:ivar, 'SomeIvarJob', nil) + Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob, nil) Resque::Scheduler.handle_delayed_items end diff --git a/test/scheduler_test.rb b/test/scheduler_test.rb index 98b46182..7832bc5d 100644 --- a/test/scheduler_test.rb +++ b/test/scheduler_test.rb @@ -13,13 +13,8 @@ def setup Resque::Scheduler.send(:class_variable_set, :@@scheduled_jobs, {}) end - def test_enqueue_from_config_puts_stuff_in_the_resque_queue_without_class_loaded - Resque::Job.stubs(:create).once.returns(true).with('joes_queue', 'BigJoesJob', '/tmp') - Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'BigJoesJob', 'args' => "/tmp", 'queue' => 'joes_queue') - end - def test_enqueue_from_config_puts_stuff_in_the_resque_queue - Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp') + Resque::Job.stubs(:create).once.returns(true).with(:ivar, SomeIvarJob, '/tmp') Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp") end