Class: CalendarToQueue::Queue
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CalendarToQueue::Queue
- Defined in:
- app/models/calendar_to_queue/queue.rb
Class Method Summary collapse
- .client ⇒ Object
- .create_queue(name) ⇒ Object
- .deliver(push) ⇒ Object
-
.lookup(name) ⇒ Object
Creates or finds.
Instance Method Summary collapse
Class Method Details
.client ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/models/calendar_to_queue/queue.rb', line 47 def self.client @@client ||= Aws::SQS::Client.new( region: 'us-east-1', access_key_id: CalendarToQueue.config.aws_access_key_id, secret_access_key: CalendarToQueue.config.aws_secret_access_key ) end |
.create_queue(name) ⇒ Object
29 30 31 |
# File 'app/models/calendar_to_queue/queue.rb', line 29 def self.create_queue(name) create(name: name) end |
.deliver(push) ⇒ Object
6 7 8 9 10 11 |
# File 'app/models/calendar_to_queue/queue.rb', line 6 def self.deliver(push) unless push.queue_name.blank? queue = lookup(push.queue_name) queue.deliver(push) end end |
.lookup(name) ⇒ Object
Creates or finds
25 26 27 |
# File 'app/models/calendar_to_queue/queue.rb', line 25 def self.lookup(name) find_by_name(name) || create_queue(name) end |
Instance Method Details
#deliver(push) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/calendar_to_queue/queue.rb', line 13 def deliver(push) begin CalendarToQueue::Queue.client.({ queue_url: url, message_body: JSON.generate(push.payload), }) rescue Aws::SQS::Errors::ServiceError => e CalendarToQueue.logger.error("Error sending to queue #{self.name}, push: #{}AWS QUEUE: #{e.context}: #{e.code}") end end |