Class: Shoryuken::Processor

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/shoryuken/processor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#elapsed, #fire_event, #logger, #unparse_queues, #worker_name

Constructor Details

#initialize(queue, sqs_msg) ⇒ Processor

Returns a new instance of Processor.


11
12
13
14
# File 'lib/shoryuken/processor.rb', line 11

def initialize(queue, sqs_msg)
  @queue   = queue
  @sqs_msg = sqs_msg
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue


5
6
7
# File 'lib/shoryuken/processor.rb', line 5

def queue
  @queue
end

#sqs_msgObject (readonly)

Returns the value of attribute sqs_msg


5
6
7
# File 'lib/shoryuken/processor.rb', line 5

def sqs_msg
  @sqs_msg
end

Class Method Details

.process(queue, sqs_msg) ⇒ Object


7
8
9
# File 'lib/shoryuken/processor.rb', line 7

def self.process(queue, sqs_msg)
  new(queue, sqs_msg).process
end

Instance Method Details

#processObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shoryuken/processor.rb', line 16

def process
  return logger.error { "No worker found for #{queue}" } unless worker

  Shoryuken::Logging.with_context("#{worker_name(worker.class, sqs_msg, body)}/#{queue}/#{sqs_msg.message_id}") do
    worker.class.server_middleware.invoke(worker, queue, sqs_msg, body) do
      worker.perform(sqs_msg, body)
    end
  end
rescue Exception => ex
  logger.error { "Processor failed: #{ex.message}" }
  logger.error { ex.backtrace.join("\n") } unless ex.backtrace.nil?

  raise
end