aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/queue_adapters
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2016-01-27 11:29:18 -0500
committerJon Moss <me@jonathanmoss.me>2016-01-27 12:49:35 -0500
commita9a64c490dd5f5038b05338debe439855323afb5 (patch)
treeb15bd6f3de87dc1162c22c1eb2dbc9bfe9834cdb /activejob/lib/active_job/queue_adapters
parent3844854af109fb9eee75c90bacf8bf87eb2bf968 (diff)
downloadrails-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/lib/active_job/queue_adapters')
-rw-r--r--activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb15
1 files changed, 13 insertions, 2 deletions
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: