Class: Lambdakiq::Queue

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_name) ⇒ Queue

Returns a new instance of Queue.



7
8
9
10
11
# File 'lib/lambdakiq/queue.rb', line 7

def initialize(queue_name)
  @queue_name = queue_name
  @queue_url = get_queue_url
  attributes
end

Instance Attribute Details

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



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

def queue_name
  @queue_name
end

#queue_urlObject (readonly)

Returns the value of attribute queue_url.



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

def queue_url
  @queue_url
end

Instance Method Details

#attributesObject



17
18
19
20
21
22
# File 'lib/lambdakiq/queue.rb', line 17

def attributes
  @attributes ||= client.get_queue_attributes({
    queue_url: queue_url,
    attribute_names: ['All']
  }).attributes
end

#fifo?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/lambdakiq/queue.rb', line 32

def fifo?
  queue_name.ends_with?('.fifo')
end

#max_receive_countObject



28
29
30
# File 'lib/lambdakiq/queue.rb', line 28

def max_receive_count
  redrive_policy&.dig('maxReceiveCount')&.to_i || 1
end

#redrive_policyObject



24
25
26
# File 'lib/lambdakiq/queue.rb', line 24

def redrive_policy
  @redrive_policy ||= attributes['RedrivePolicy'] ? JSON.parse(attributes['RedrivePolicy']) : nil
end

#send_message(job, options = {}) ⇒ Object



13
14
15
# File 'lib/lambdakiq/queue.rb', line 13

def send_message(job, options = {})
  client.send_message send_message_params(job, options)
end