Sha256: f41cfdd4bcc339b86be2b20c7c97075456100e108c279fb01af772f4ad062a69

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

module Propono
  class SqsMessage
    attr_reader :context, :message, :receipt_handle, :failure_count
    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

    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

    def ==(other)
      other.is_a?(SqsMessage) && other.receipt_handle == @receipt_handle
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
propono-3.0.0 lib/propono/components/sqs_message.rb
propono-2.2.1 lib/propono/components/sqs_message.rb
propono-2.2.0 lib/propono/components/sqs_message.rb
propono-2.1.0 lib/propono/components/sqs_message.rb
propono-2.0.0 lib/propono/components/sqs_message.rb
propono-2.0.0.rc3 lib/propono/components/sqs_message.rb
propono-2.0.0.rc2 lib/propono/components/sqs_message.rb
propono-2.0.0.rc1 lib/propono/components/sqs_message.rb