Class: Lambdakiq::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/lambdakiq/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/lambdakiq/record.rb', line 4

def data
  @data
end

Instance Method Details

#attributesObject



26
27
28
# File 'lib/lambdakiq/record.rb', line 26

def attributes
  data['attributes']
end

#bodyObject



10
11
12
# File 'lib/lambdakiq/record.rb', line 10

def body
  data['body']
end

#fifo_delay_secondsObject



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

Returns:

  • (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_timeoutObject



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_idObject



14
15
16
# File 'lib/lambdakiq/record.rb', line 14

def message_id
  data['messageId']
end

#next_visibility_timeoutObject



53
54
55
# File 'lib/lambdakiq/record.rb', line 53

def next_visibility_timeout
  @next_visibility_timeout ||= Backoff.backoff(receive_count)
end

#queue_nameObject



22
23
24
# File 'lib/lambdakiq/record.rb', line 22

def queue_name
  @queue_name ||= data['eventSourceARN'].split(':').last
end

#receipt_handleObject



18
19
20
# File 'lib/lambdakiq/record.rb', line 18

def receipt_handle
  data['receiptHandle']
end

#receive_countObject



49
50
51
# File 'lib/lambdakiq/record.rb', line 49

def receive_count
  @receive_count ||= attributes['ApproximateReceiveCount'].to_i
end

#sent_atObject



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