Class: Propono::SqsMessage
- Inherits:
-
Object
- Object
- Propono::SqsMessage
- Includes:
- Sqs
- Defined in:
- lib/propono/components/sqs_message.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#failure_count ⇒ Object
readonly
Returns the value of attribute failure_count.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#raw_message ⇒ Object
readonly
Returns the value of attribute raw_message.
-
#receipt_handle ⇒ Object
readonly
Returns the value of attribute receipt_handle.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(raw_message) ⇒ SqsMessage
constructor
A new instance of SqsMessage.
- #to_json_with_exception(exception) ⇒ Object
Constructor Details
#initialize(raw_message) ⇒ SqsMessage
Returns a new instance of SqsMessage.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/propono/components/sqs_message.rb', line 6 def initialize() raw_body = ["Body"] @raw_body_json = JSON.parse(raw_body) body = JSON.parse(@raw_body_json["Message"]) @raw_message = @context = Propono::Utils.symbolize_keys body @failure_count = context[:num_failures] || 0 @message = context.delete(:message) @receipt_handle = ["receipt_handle"] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/propono/components/sqs_message.rb', line 5 def context @context end |
#failure_count ⇒ Object (readonly)
Returns the value of attribute failure_count.
5 6 7 |
# File 'lib/propono/components/sqs_message.rb', line 5 def failure_count @failure_count end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/propono/components/sqs_message.rb', line 5 def @message end |
#raw_message ⇒ Object (readonly)
Returns the value of attribute raw_message.
5 6 7 |
# File 'lib/propono/components/sqs_message.rb', line 5 def @raw_message end |
#receipt_handle ⇒ Object (readonly)
Returns the value of attribute receipt_handle.
5 6 7 |
# File 'lib/propono/components/sqs_message.rb', line 5 def receipt_handle @receipt_handle end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 |
# File 'lib/propono/components/sqs_message.rb', line 32 def ==(other) other.is_a?(SqsMessage) && other.receipt_handle == @receipt_handle end |
#to_json_with_exception(exception) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/propono/components/sqs_message.rb', line 18 def to_json_with_exception(exception) = @raw_body_json.dup context = {} context[:id] = @context[:id] context[:message] = @message context[:last_exception_message] = exception. context[:last_exception_stack_trace] = exception.backtrace context[:last_exception_time] = Time.now context[:num_failures] = failure_count + 1 context[:last_context] = @context ['Message'] = context.to_json JSON.pretty_generate() end |