Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Validate job class before delayed enqueue.

Resque does check of the job class before enqueue it.
Resque-scheduler doesn't do that before put them into the schedule.
That is why we see error no on schedule but at execution.
This is not correct. We should do same checks as redis do:
https://github.com/defunkt/resque/blob/master/lib/resque/job.rb#L39

Unfortunatelly we can not reuse code.
  • Loading branch information...
commit 7f65bba3bf9ec066b114c95a42b3a8b58736ff16 1 parent b2fe389
@bogdan bogdan authored
Showing with 20 additions and 0 deletions.
  1. +11 −0 lib/resque_scheduler.rb
  2. +9 −0 test/delayed_queue_test.rb
View
11 lib/resque_scheduler.rb
@@ -85,6 +85,7 @@ def remove_schedule(name)
# for queueing. Until timestamp is in the past, the job will
# sit in the schedule list.
def enqueue_at(timestamp, klass, *args)
+ validate_job!(klass)
delayed_push(timestamp, job_to_hash(klass, args))
end
@@ -194,6 +195,16 @@ def clean_up_timestamp(key, timestamp)
end
end
+ def validate_job!(klass)
+ if klass.to_s.empty?
+ raise Resque::NoClassError.new("Jobs must be given a class.")
+ end
+
+ unless queue_from_class(klass)
+ raise Resque::NoQueueError.new("Jobs must be placed onto a queue.")
+ end
+ end
+
end
Resque.extend ResqueScheduler
View
9 test/delayed_queue_test.rb
@@ -217,4 +217,13 @@ def test_remove_specific_item_in_group_of_other_items_at_different_timestamps
assert_equal(2, Resque.remove_delayed(SomeIvarJob, "bar"))
assert_equal(2, Resque.count_all_scheduled_jobs)
end
+
+ def test_invalid_job_class
+ assert_raise Resque::NoClassError do
+ Resque.enqueue_in(10, nil)
+ end
+ assert_raise Resque::NoQueueError do
+ Resque.enqueue_in(10, String) # string serves as invalid Job class
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.