Class: Propono::SqsMessage
- Inherits:
-
Object
- Object
- Propono::SqsMessage
- 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.
-
#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.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/propono/components/sqs_message.rb', line 4 def initialize() raw_body = .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 = .receipt_handle end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/propono/components/sqs_message.rb', line 3 def context @context end |
#failure_count ⇒ Object (readonly)
Returns the value of attribute failure_count.
3 4 5 |
# File 'lib/propono/components/sqs_message.rb', line 3 def failure_count @failure_count end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
3 4 5 |
# File 'lib/propono/components/sqs_message.rb', line 3 def @message end |
#receipt_handle ⇒ Object (readonly)
Returns the value of attribute receipt_handle.
3 4 5 |
# File 'lib/propono/components/sqs_message.rb', line 3 def receipt_handle @receipt_handle end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/propono/components/sqs_message.rb', line 15 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 |