Class: Railbox::Queue::HttpQueue
- Defined in:
- lib/railbox/queue/http_queue.rb
Overview
HttpQueue is responsible for enqueuing HTTP request actions into the transactional outbox.
Usage example:
Railbox::HttpQueue.enqueue(
url: "https://example.com/api",
method: :post,
body: { data: 1 },
headers: { "Authorization" => "Bearer ..." },
query: { foo: "bar" },
meta: { correlation_id: "123" }
)
This creates a Railbox::TransactionalOutboxMutator record, which will be processed later by a background worker, providing reliable, traceable, and decoupled execution of HTTP requests.
A ValidationError will be raised if the url, method, or body are invalid.
Constant Summary collapse
- OPTIONS =
i[query group].freeze
- METHODS =
i[get post put patch delete].freeze
Class Method Summary collapse
-
.enqueue(url:, method: :post, body: {}, headers: {}, **opts) ⇒ Boolean
Enqueues an HTTP request action for asynchronous processing via the transactional outbox.
Class Method Details
.enqueue(url:, method: :post, body: {}, headers: {}, **opts) ⇒ Boolean
Enqueues an HTTP request action for asynchronous processing via the transactional outbox.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/railbox/queue/http_queue.rb', line 35 def enqueue(url:, method: :post, body: {}, headers: {}, **opts) opts.deep_symbolize_keys!.slice!(*OPTIONS) (url, method, body) to_queue( action_type: 'http_request', action_data: {url: url, method_name: method}, body: body, headers: headers, status: 'in_progress', **opts ) true end |