class Propono::SqsMessage

Attributes

context[R]
failure_count[R]
message[R]
receipt_handle[R]

Public Class Methods

new(raw_message) click to toggle source
# File lib/propono/components/sqs_message.rb, line 4
def initialize(raw_message)
  raw_body = raw_message.body
  @raw_body_json = JSON.parse(raw_body)
  body = JSON.parse(@raw_body_json["Message"])

  @context        = Propono::Utils.symbolize_keys body
  @failure_count  = context[:num_failures] || 0
  @message        = context.delete(:message)
  @receipt_handle = raw_message.receipt_handle
end

Public Instance Methods

==(other) click to toggle source
# File lib/propono/components/sqs_message.rb, line 29
def ==(other)
  other.is_a?(SqsMessage) && other.receipt_handle == @receipt_handle
end
to_json_with_exception(exception) click to toggle source
# File lib/propono/components/sqs_message.rb, line 15
def to_json_with_exception(exception)
  message = @raw_body_json.dup
  context = {}
  context[:id] = @context[:id]
  context[:message] = @message
  context[:last_exception_message] = exception.message
  context[:last_exception_stack_trace] = exception.backtrace
  context[:last_exception_time] = Time.now
  context[:num_failures] = failure_count + 1
  context[:last_context] = @context
  message['Message'] = context.to_json
  JSON.pretty_generate(message)
end