Class: Kindly::Queue
- Inherits:
-
Object
- Object
- Kindly::Queue
- Defined in:
- lib/kindly/queue.rb
Instance Method Summary collapse
- #add(job_name, job_id) ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #pop(job_name) ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
7 8 9 |
# File 'lib/kindly/queue.rb', line 7 def initialize @sqs = Aws::SQS::Client.new(region: 'us-west-2') end |
Instance Method Details
#add(job_name, job_id) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kindly/queue.rb', line 11 def add(job_name, job_id) @sqs.({ queue_url: queue_url(job_name), message_body: "#{@job_name} has been requested.", message_attributes: { 'JobId' => { string_value: job_id, data_type: "String", }, }, }) end |
#pop(job_name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kindly/queue.rb', line 24 def pop(job_name) response = @sqs.({ queue_url: queue_url(job_name), message_attribute_names: ['JobId'], max_number_of_messages: 1 }) raise (job_name) if response..length > 1 return nil if response..length == 0 = response.[0] job_id = .['JobId'].string_value @sqs.({ queue_url: queue_url(job_name), receipt_handle: .receipt_handle }) job_id end |