Skip to content

Commit

Permalink
Compatibility with Rails 5
Browse files Browse the repository at this point in the history
  • Loading branch information
avokhmin committed Jan 20, 2016
1 parent 9ac47e2 commit 6635277
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions lib/shoryuken/extensions/active_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,43 @@ module QueueAdapters
#
# Rails.application.config.active_job.queue_adapter = :shoryuken
class ShoryukenAdapter
class << self
def enqueue(job) #:nodoc:
register_worker!(job)
def enqueue(job) #:nodoc:
register_worker!(job)

queue = Shoryuken::Client.queues(job.queue_name)
queue.send_message(message(job))
end
queue = Shoryuken::Client.queues(job.queue_name)
queue.send_message(message(job))
end

def enqueue_at(job, timestamp) #:nodoc:
register_worker!(job)
def enqueue_at(job, timestamp) #:nodoc:
register_worker!(job)

delay = (timestamp - Time.current.to_f).round
raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
delay = (timestamp - Time.current.to_f).round
raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes

queue = Shoryuken::Client.queues(job.queue_name)
queue.send_message(message(job, delay_seconds: delay))
end
queue = Shoryuken::Client.queues(job.queue_name)
queue.send_message(message(job, delay_seconds: delay))
end

private
private

def message(job, options = {})
body = job.serialize
def message(job, options = {})
body = job.serialize

{ message_body: body,
message_attributes: message_attributes }.merge(options)
end
{ message_body: body,
message_attributes: message_attributes }.merge(options)
end

def register_worker!(job)
Shoryuken.register_worker(job.queue_name, JobWrapper)
end
def register_worker!(job)
Shoryuken.register_worker(job.queue_name, JobWrapper)
end

def message_attributes
@message_attributes ||= {
'shoryuken_class' => {
string_value: JobWrapper.to_s,
data_type: 'String'
}
def message_attributes
@message_attributes ||= {
'shoryuken_class' => {
string_value: JobWrapper.to_s,
data_type: 'String'
}
end
}
end

class JobWrapper #:nodoc:
Expand Down

0 comments on commit 6635277

Please sign in to comment.