Skip to content
Browse files

update README

remove puts from tests
  • Loading branch information...
1 parent 0c96320 commit ca46fed10b1cac2bd81f30940eaeab4eab380e43 @yaauie yaauie committed Nov 2, 2011
Showing with 6 additions and 3 deletions.
  1. +6 −0 README.markdown
  2. +0 −3 test/scheduler_hooks_test.rb
6 README.markdown
@@ -128,6 +128,12 @@ down when a particular job is supposed to be queue, they will simply "catch up"
once they are started again. Jobs are guaranteed to run (provided they make it
into the delayed queue) after their given queue_at time has passed.
+Similar to `before_enqueue` and `after_enqueue` hooks provided in Resque
+(>= 1.19.1), your jobs can specify one or more `before_schedule` and
+`after_schedule` hooks, to be run before or after scheduling. If *any* of your
+`before_schedule` hooks returns `false`, the job will *not* be scheduled and
+your `after_schedule` hooks will *not* be run.
One other thing to note is that insertion into the delayed queue is O(log(n))
since the jobs are stored in a redis sorted set (zset). I can't imagine this
being an issue for someone since redis is stupidly fast even at log(n), but full
3 test/scheduler_hooks_test.rb
@@ -5,7 +5,6 @@ class JobThatCannotBeScheduledWithoutArguments < Resque::Job
@queue = :job_that_cannot_be_scheduled_without_arguments
def self.perform(*x);end
def self.before_schedule_return_nil_if_arguments_not_supplied(*args)
- puts "running"
counters[:before_schedule] += 1
return false if args.empty?
@@ -36,7 +35,6 @@ def setup
def test_schedule_job_that_can_reject_being_scheduled_but_doesnt
enqueue_time = + 12
- puts JobThatCannotBeScheduledWithoutArguments.clean.counters.inspect
Resque.enqueue_at(enqueue_time, JobThatCannotBeScheduledWithoutArguments.clean, :foo)
assert_equal(1, Resque.redis.llen("delayed:#{enqueue_time.to_i}").to_i, "delayed queue should have one entry now")
assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule), "The delayed_queue_schedule should have 1 entry now")
@@ -46,7 +44,6 @@ def test_schedule_job_that_can_reject_being_scheduled_but_doesnt
def test_schedule_job_that_can_reject_being_scheduled_and_does
enqueue_time = + 60
- puts JobThatCannotBeScheduledWithoutArguments.clean.counters.inspect
assert_equal(0, JobThatCannotBeScheduledWithoutArguments.counters[:before_schedule], 'before_schedule should be zero')
Resque.enqueue_at(enqueue_time, JobThatCannotBeScheduledWithoutArguments.clean)
assert_equal(0, Resque.redis.llen("delayed:#{enqueue_time.to_i}").to_i, "job should not have been put in queue")

0 comments on commit ca46fed

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