Class: Shoryuken::Worker::InlineExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/shoryuken/worker/inline_executor.rb

Overview

Executor that processes jobs synchronously in the current thread. Useful for testing and development environments.

Class Method Summary collapse

Class Method Details

.perform_async(worker_class, body, options = {}) ⇒ Object

Processes a job synchronously in the current thread

Parameters:

  • worker_class (Class)

    the worker class that will process the message

  • body (Object)

    the message body

  • options (Hash) (defaults to: {})

    inline execution options

Options Hash (options):

  • :queue (String)

    override the default queue name

  • :message_attributes (Hash)

    custom message attributes

Returns:

  • (Object)

    the result of the worker’s perform method



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shoryuken/worker/inline_executor.rb', line 17

def perform_async(worker_class, body, options = {})
  body = JSON.dump(body) if body.is_a?(Hash)
  queue_name = options.delete(:queue) || worker_class.get_shoryuken_options['queue']
  message_attributes = options.delete(:message_attributes) || {}
  message_attributes['shoryuken_class'] = {
    string_value: worker_class.to_s,
    data_type: 'String'
  }

  sqs_msg = InlineMessage.new(
    body: body,
    attributes: nil,
    md5_of_body: nil,
    md5_of_message_attributes: nil,
    message_attributes: message_attributes,
    message_id: nil,
    receipt_handle: nil,
    delete: nil,
    queue_name: queue_name
  )

  call(worker_class, sqs_msg)
end

.perform_in(worker_class, _interval, body, options = {}) ⇒ Object

Processes a job synchronously, ignoring the delay interval

Parameters:

  • worker_class (Class)

    the worker class that will process the message

  • _interval (Integer, Float)

    ignored for inline execution

  • body (Object)

    the message body

  • options (Hash) (defaults to: {})

    inline execution options

Options Hash (options):

  • :queue (String)

    override the default queue name

  • :message_attributes (Hash)

    custom message attributes

Returns:

  • (Object)

    the result of the worker’s perform method



50
51
52
# File 'lib/shoryuken/worker/inline_executor.rb', line 50

def perform_in(worker_class, _interval, body, options = {})
  worker_class.perform_async(body, options)
end