Class: Barbeque::MessageEnqueuingService
- Inherits:
-
Object
- Object
- Barbeque::MessageEnqueuingService
- Defined in:
- app/services/barbeque/message_enqueuing_service.rb
Defined Under Namespace
Classes: BadRequest
Constant Summary collapse
- DEFAULT_QUEUE =
ENV['BARBEQUE_DEFAULT_QUEUE'] || 'default'
- VERIFY_ENQUEUED_JOBS =
ENV['BARBEQUE_VERIFY_ENQUEUED_JOBS'] || '0'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(application:, job:, message:, queue: nil, delay_seconds: nil) ⇒ MessageEnqueuingService
constructor
A new instance of MessageEnqueuingService.
-
#run ⇒ String
Message_id.
Constructor Details
#initialize(application:, job:, message:, queue: nil, delay_seconds: nil) ⇒ MessageEnqueuingService
Returns a new instance of MessageEnqueuingService.
19 20 21 22 23 24 25 |
# File 'app/services/barbeque/message_enqueuing_service.rb', line 19 def initialize(application:, job:, message:, queue: nil, delay_seconds: nil) @application = application @job = job @queue = queue || DEFAULT_QUEUE @message = @delay_seconds = delay_seconds end |
Class Method Details
.sqs_client ⇒ Object
10 11 12 |
# File 'app/services/barbeque/message_enqueuing_service.rb', line 10 def self.sqs_client @sqs_client ||= Aws::SQS::Client.new end |
Instance Method Details
#run ⇒ String
Returns message_id.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/barbeque/message_enqueuing_service.rb', line 28 def run queue_url = Barbeque::JobQueue.queue_url_from_name(@queue) if VERIFY_ENQUEUED_JOBS == '1' unless Barbeque::JobDefinition.joins(:app).merge(Barbeque::App.where(name: @application)).where(job: @job).exists? raise BadRequest.new("JobDefinition '#{@job}' isn't defined in '#{@application}' application") end end response = Barbeque::MessageEnqueuingService.sqs_client.( queue_url: queue_url, message_body: .to_json, delay_seconds: @delay_seconds, ) response. rescue Aws::SQS::Errors::InvalidParameterValue => e raise BadRequest.new(e.) end |