mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Add support for AJ's :wait option
This commit is contained in:
parent
305c3865d9
commit
3b233c558a
3 changed files with 8 additions and 4 deletions
|
@ -21,7 +21,7 @@ end
|
|||
require "sidekiq/middleware/current_attributes"
|
||||
Sidekiq::CurrentAttributes.persist(Myapp::Current) # Your AS::CurrentAttributes singleton
|
||||
```
|
||||
- Implement `queue_as` and `wait_until` for ActiveJob compatibility [#5003]
|
||||
- Implement `queue_as`, `wait` and `wait_until` for ActiveJob compatibility [#5003]
|
||||
- Retry Redis operation if we get an `UNBLOCKED` Redis error. [#4985]
|
||||
- Run existing signal traps, if any, before running Sidekiq's trap. [#4991]
|
||||
|
||||
|
|
|
@ -176,12 +176,12 @@ module Sidekiq
|
|||
@opts = opts
|
||||
|
||||
# ActiveJob compatibility
|
||||
interval = @opts.delete(:wait_until)
|
||||
interval = @opts.delete(:wait_until) || @opts.delete(:wait)
|
||||
at(interval) if interval
|
||||
end
|
||||
|
||||
def set(options)
|
||||
interval = options.delete(:wait_until)
|
||||
interval = options.delete(:wait_until) || options.delete(:wait)
|
||||
@opts.merge!(options)
|
||||
at(interval) if interval
|
||||
self
|
||||
|
@ -204,6 +204,7 @@ module Sidekiq
|
|||
int = interval.to_f
|
||||
now = Time.now.to_f
|
||||
ts = (int < 1_000_000_000 ? now + int : int)
|
||||
# Optimization to enqueue something now that is scheduled to go out now or in the past
|
||||
@opts["at"] = ts if ts > now
|
||||
self
|
||||
end
|
||||
|
|
|
@ -16,9 +16,12 @@ describe Sidekiq::Worker do
|
|||
it "provides basic ActiveJob compatibilility" do
|
||||
q = Sidekiq::ScheduledSet.new
|
||||
assert_equal 0, q.size
|
||||
jid = SetWorker.set(wait_until: 1.hour).perform_async(123)
|
||||
jid = SetWorker.set(wait_until: 1.hour.from_now).perform_async(123)
|
||||
assert jid
|
||||
assert_equal 1, q.size
|
||||
jid = SetWorker.set(wait: 1.hour).perform_async(123)
|
||||
assert jid
|
||||
assert_equal 2, q.size
|
||||
|
||||
q = Sidekiq::Queue.new("foo")
|
||||
assert_equal 0, q.size
|
||||
|
|
Loading…
Add table
Reference in a new issue