Class: Qurd::Processor

Inherits:
Object
  • Object
show all
Includes:
Mixins::AwsClients, Mixins::Configuration
Defined in:
lib/qurd/processor.rb

Overview

Use a Listener to act on an AWS SQS message

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::AwsClients

#aws_client, #aws_retryable

Methods included from Mixins::Configuration

#qurd_config, #qurd_configuration, #qurd_logger, #qurd_logger!

Constructor Details

#initialize(listener, msg, listener_name, queue_url) ⇒ Processor

Returns a new instance of Processor.

Parameters:



16
17
18
19
20
21
22
23
24
25
# File 'lib/qurd/processor.rb', line 16

def initialize(listener, msg, listener_name, queue_url)
  @listener = listener
  @message = Message.new(
    message: msg,
    name: listener_name,
    queue_url: queue_url,
    aws_credentials: @listener.aws_credentials,
    region: @listener.region
  )
end

Instance Attribute Details

#listenerQurd::Listener (readonly)

Returns:



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

def listener
  @listener
end

#messageObject (readonly)

Returns the value of attribute message.



12
# File 'lib/qurd/processor.rb', line 12

attr_reader :listener, :message

Instance Method Details

#inspectObject



45
46
47
48
49
50
51
# File 'lib/qurd/processor.rb', line 45

def inspect
  format('<Qurd::Processor:%x listener:%s message:%s>',
         object_id,
         listener.inspect,
         message.inspect
  )
end

#processObject

Process an SQS message, by instantiating an instance of each action, calling run_before, run, and run_after, and deleting the message.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/qurd/processor.rb', line 29

def process
  qurd_logger.info("Processing #{listener.name} " \
                   "action:#{message.action} " \
                   "event:#{message.message.Event}")

  if message.action
    instantiate_actions
    run_before
    run_action
    run_after
  end

  message.delete
end