diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-01-27 11:29:18 -0500 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-01-27 12:49:35 -0500 |
commit | a9a64c490dd5f5038b05338debe439855323afb5 (patch) | |
tree | b15bd6f3de87dc1162c22c1eb2dbc9bfe9834cdb /activejob | |
parent | 3844854af109fb9eee75c90bacf8bf87eb2bf968 (diff) | |
download | rails-a9a64c490dd5f5038b05338debe439855323afb5.tar.gz rails-a9a64c490dd5f5038b05338debe439855323afb5.tar.bz2 rails-a9a64c490dd5f5038b05338debe439855323afb5.zip |
Update ActiveJob adapter for sucker_punch 2.0
This PR includes two changes for 2.0.0:
- Breaking API change around `async.perform` --> `perform_async`
- New addition of `perform_in`, which now allows end users of the
adapter to use the `enqueued_at` public API method.
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/lib/active_job/queue_adapters.rb | 2 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb index aeb1fe1e73..2c5039ef4d 100644 --- a/activejob/lib/active_job/queue_adapters.rb +++ b/activejob/lib/active_job/queue_adapters.rb @@ -27,7 +27,7 @@ module ActiveJob # | Resque | Yes | Yes | Yes (Gem) | Queue | Global | Yes | # | Sidekiq | Yes | Yes | Yes | Queue | No | Job | # | Sneakers | Yes | Yes | No | Queue | Queue | No | - # | Sucker Punch | Yes | Yes | No | No | No | No | + # | Sucker Punch | Yes | Yes | Yes | No | No | No | # | Active Job Async | Yes | Yes | Yes | No | No | No | # | Active Job Inline | No | Yes | N/A | N/A | N/A | N/A | # diff --git a/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb b/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb index c6c35f8ab4..1037084341 100644 --- a/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb @@ -19,11 +19,22 @@ module ActiveJob # Rails.application.config.active_job.queue_adapter = :sucker_punch class SuckerPunchAdapter def enqueue(job) #:nodoc: - JobWrapper.new.async.perform job.serialize + if JobWrapper.respond_to?(:perform_async) + # sucker_punch 2.0 API + JobWrapper.perform_async job.serialize + else + # sucker_punch 1.0 API + JobWrapper.new.async.perform job.serialize + end end def enqueue_at(job, timestamp) #:nodoc: - raise NotImplementedError, "This queueing backend does not support scheduling jobs. To see what features are supported go to http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html" + if JobWrapper.respond_to?(:perform_in) + delay = timestamp - Time.current.to_f + JobWrapper.perform_in delay, job.serialize + else + raise NotImplementedError, 'sucker_punch 1.0 does not support `enqueued_at`. Please upgrade to version ~> 2.0.0 to enable this behavior.' + end end class JobWrapper #:nodoc: |