Skip to content
This repository
Browse code

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 Gusiev authored January 14, 2011
11  lib/resque_scheduler.rb
@@ -85,6 +85,7 @@ def remove_schedule(name)
85 85
   # for queueing.  Until timestamp is in the past, the job will
86 86
   # sit in the schedule list.
87 87
   def enqueue_at(timestamp, klass, *args)
  88
+    validate_job!(klass)
88 89
     delayed_push(timestamp, job_to_hash(klass, args))
89 90
   end
90 91
 
@@ -194,6 +195,16 @@ def clean_up_timestamp(key, timestamp)
194 195
       end
195 196
     end
196 197
 
  198
+    def validate_job!(klass)
  199
+      if klass.to_s.empty?
  200
+        raise Resque::NoClassError.new("Jobs must be given a class.")
  201
+      end
  202
+
  203
+      unless queue_from_class(klass)
  204
+        raise Resque::NoQueueError.new("Jobs must be placed onto a queue.")
  205
+      end
  206
+    end
  207
+
197 208
 end
198 209
 
199 210
 Resque.extend ResqueScheduler
9  test/delayed_queue_test.rb
@@ -217,4 +217,13 @@ def test_remove_specific_item_in_group_of_other_items_at_different_timestamps
217 217
     assert_equal(2, Resque.remove_delayed(SomeIvarJob, "bar"))
218 218
     assert_equal(2, Resque.count_all_scheduled_jobs)
219 219
   end
  220
+
  221
+  def test_invalid_job_class
  222
+    assert_raise Resque::NoClassError do
  223
+      Resque.enqueue_in(10, nil)
  224
+    end
  225
+    assert_raise Resque::NoQueueError do
  226
+      Resque.enqueue_in(10, String) # string serves as invalid Job class
  227
+    end
  228
+  end
220 229
 end

0 notes on commit 7f65bba

Please sign in to comment.
Something went wrong with that request. Please try again.