Class: Lambdakiq::Record
- Inherits:
-
Object
- Object
- Lambdakiq::Record
- Defined in:
- lib/lambdakiq/record.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #attributes ⇒ Object
- #body ⇒ Object
- #fifo_delay_seconds ⇒ Object
- #fifo_delay_seconds? ⇒ Boolean
- #fifo_delay_visibility_timeout ⇒ Object
-
#initialize(data) ⇒ Record
constructor
A new instance of Record.
- #message_id ⇒ Object
- #next_visibility_timeout ⇒ Object
- #queue_name ⇒ Object
- #receipt_handle ⇒ Object
- #receive_count ⇒ Object
- #sent_at ⇒ Object
Constructor Details
#initialize(data) ⇒ Record
Returns a new instance of Record.
6 7 8 |
# File 'lib/lambdakiq/record.rb', line 6 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/lambdakiq/record.rb', line 4 def data @data end |
Instance Method Details
#attributes ⇒ Object
26 27 28 |
# File 'lib/lambdakiq/record.rb', line 26 def attributes data['attributes'] end |
#body ⇒ Object
10 11 12 |
# File 'lib/lambdakiq/record.rb', line 10 def body data['body'] end |
#fifo_delay_seconds ⇒ Object
34 35 36 |
# File 'lib/lambdakiq/record.rb', line 34 def fifo_delay_seconds data.dig('messageAttributes', 'delay_seconds', 'stringValue').try(:to_i) end |
#fifo_delay_seconds? ⇒ Boolean
38 39 40 |
# File 'lib/lambdakiq/record.rb', line 38 def fifo_delay_seconds? fifo_delay_seconds && (sent_at + fifo_delay_seconds).future? end |
#fifo_delay_visibility_timeout ⇒ Object
30 31 32 |
# File 'lib/lambdakiq/record.rb', line 30 def fifo_delay_visibility_timeout fifo_delay_seconds - (Time.current - sent_at).to_i end |
#message_id ⇒ Object
14 15 16 |
# File 'lib/lambdakiq/record.rb', line 14 def data['messageId'] end |
#next_visibility_timeout ⇒ Object
53 54 55 |
# File 'lib/lambdakiq/record.rb', line 53 def next_visibility_timeout @next_visibility_timeout ||= Backoff.backoff(receive_count) end |
#queue_name ⇒ Object
22 23 24 |
# File 'lib/lambdakiq/record.rb', line 22 def queue_name @queue_name ||= data['eventSourceARN'].split(':').last end |
#receipt_handle ⇒ Object
18 19 20 |
# File 'lib/lambdakiq/record.rb', line 18 def receipt_handle data['receiptHandle'] end |
#receive_count ⇒ Object
49 50 51 |
# File 'lib/lambdakiq/record.rb', line 49 def receive_count @receive_count ||= attributes['ApproximateReceiveCount'].to_i end |
#sent_at ⇒ Object
42 43 44 45 46 47 |
# File 'lib/lambdakiq/record.rb', line 42 def sent_at @sent_at ||= begin ts = attributes['SentTimestamp'].to_i / 1000 Time.zone ? Time.zone.at(ts) : Time.at(ts) end end |