Class: ActiveJob::QueueAdapters::ShoryukenConcurrentSendAdapter

Inherits:
ShoryukenAdapter
  • Object
show all
Defined in:
lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb

Overview

Shoryuken concurrent adapter for Active Job

This adapter sends messages asynchronously (ie non-blocking) and allows the caller to set up handlers for both success and failure

To use this adapter, set up as:

success_handler = ->(response, job, options) { StatsD.increment(“#jobjob.classjob.class.name.success”) } error_handler = ->(err, job, options) { StatsD.increment(“#jobjob.classjob.class.name.failure”) }

adapter = ActiveJob::QueueAdapters::ShoryukenConcurrentSendAdapter.new(success_handler, error_handler)

config.active_job.queue_adapter = adapter

Instance Method Summary collapse

Methods inherited from ShoryukenAdapter

enqueue, #enqueue_after_transaction_commit?, enqueue_at, #enqueue_at, instance, #stopping?

Constructor Details

#initialize(success_handler = nil, error_handler = nil) ⇒ ShoryukenConcurrentSendAdapter

Returns a new instance of ShoryukenConcurrentSendAdapter.



21
22
23
24
# File 'lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb', line 21

def initialize(success_handler = nil, error_handler = nil)
  @success_handler = success_handler
  @error_handler = error_handler
end

Instance Method Details

#enqueue(job, options = {}) ⇒ Object



26
27
28
# File 'lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb', line 26

def enqueue(job, options = {})
  send_concurrently(job, options) { |f_job, f_options| super(f_job, f_options) }
end

#error_handlerObject



34
35
36
37
38
# File 'lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb', line 34

def error_handler
  @error_handler ||= lambda { |error, job, _options|
    Shoryuken.logger.warn("Failed to enqueue job: #{job.inspect} due to error: #{error}")
  }
end

#success_handlerObject



30
31
32
# File 'lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb', line 30

def success_handler
  @success_handler ||= ->(_send_message_response, _job, _options) { nil }
end