Class: Railbox::Queue::HandlingQueue

Inherits:
BaseQueue
  • Object
show all
Defined in:
lib/railbox/queue/handling_queue.rb

Overview

HandlingQueue is responsible for enqueuing “class method call” actions into the transactional outbox table.

Usage example:

Railbox::HandlingQueue.enqueue(
  service: "MyService",
  method: "perform_action",
  body: { key: "value" },
  headers: { ... },
  query: { ... },
  entity_type: "User",
  entity_id: 123,
  meta: { ... }
)

This method creates a Railbox::TransactionalOutboxMutator record to be processed by a background job later, enabling reliable, auditable, and decoupled invocation of class methods in your system.

A ValidationError is raised if the given options are invalid (for example, missing class, method, or incorrect body format).

Constant Summary collapse

OPTIONS =
%i[headers query relative_entity meta].freeze

Class Method Summary collapse

Class Method Details

.enqueue(service:, method: 'create', body: {}, **opts) ⇒ Boolean

Enqueues a class method call operation for asynchronous processing via the transactional outbox.

Parameters:

  • service (String)

    Name of the target service class (must exist).

  • method (String, Symbol) (defaults to: 'create')

    Name of the public class method to call (default: ‘create’).

  • body (Hash) (defaults to: {})

    The request payload (must be a Hash)

  • opts (Hash)

    Optional parameters: headers, query, entity_type, entity_id, meta.

Returns:

  • (Boolean)

    true if enqueuing succeeds.

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/railbox/queue/handling_queue.rb', line 35

def enqueue(service:, method: 'create', body: {}, **opts)
  opts.deep_symbolize_keys!.slice!(*OPTIONS)
  validate_options(service, method, body, **opts)

  to_queue(
    action_type: 'handler',
    action_data: {class_name: service, method_name: method},
    body:        body,
    status:      'in_progress',
    **opts
  )

  true
end