1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Rework new resque helpers

This commit is contained in:
Mike Perham 2013-09-29 14:24:25 -07:00
parent 68bfc12c39
commit 04f6a2c890
3 changed files with 15 additions and 7 deletions

View file

@ -18,7 +18,7 @@
```ruby
Sidekiq.default_worker_options = { 'queue' => 'default', 'backtrace' => true }
```
- Added two handy Sidekiq::Client class methods for scheduled jobs:
- Added two Sidekiq::Client class methods for compatibility with resque-scheduler:
`enqueue_to_in` and `enqueue_in` [#1212]
2.14.1

View file

@ -70,7 +70,8 @@ module Sidekiq
pushed ? payloads.size : nil
end
# Resque compatibility helpers.
# Resque compatibility helpers. Note all helpers
# should go through Worker#client_push.
#
# Example usage:
# Sidekiq::Client.enqueue(MyWorker, 'foo', 1, :bat => 'bar')
@ -96,9 +97,7 @@ module Sidekiq
now = Time.now.to_f
ts = (int < 1_000_000_000 ? now + int : int)
item = { 'queue' => queue, 'class' => klass, 'args' => args, 'at' => ts }
# Optimization to enqueue something now that is scheduled to go out now or in the past
item = { 'class' => klass, 'args' => args, 'at' => ts, 'queue' => queue }
item.delete('at') if ts <= now
klass.client_push(item)
@ -108,7 +107,7 @@ module Sidekiq
# Sidekiq::Client.enqueue_in(3.minutes, MyWorker, 'foo', 1, :bat => 'bar')
#
def enqueue_in(interval, klass, *args)
enqueue_to_in klass.get_sidekiq_options['queue'], interval, klass, args
klass.perform_in(interval, *args)
end
private

View file

@ -41,7 +41,16 @@ module Sidekiq
end
def perform_in(interval, *args)
Sidekiq::Client.enqueue_in(interval, self, args)
int = interval.to_f
now = Time.now.to_f
ts = (int < 1_000_000_000 ? now + int : int)
item = { 'class' => self, 'args' => args, 'at' => ts }
# Optimization to enqueue something now that is scheduled to go out now or in the past
item.delete('at') if ts <= now
client_push(item)
end
alias_method :perform_at, :perform_in