Module: Railbox

Defined in:
lib/railbox/handler/handler.rb,
lib/railbox.rb,
lib/railbox/queue/base_queue.rb,
lib/railbox/queue/http_queue.rb,
lib/railbox/http_client/faraday.rb,
lib/railbox/workers/base_worker.rb,
lib/railbox/queue/handling_queue.rb,
lib/railbox/exceptions/queue_error.rb,
lib/railbox/processors/http_processor.rb,
lib/railbox/exceptions/validation_error.rb,
lib/railbox/models/transactional_outbox.rb,
lib/railbox/processors/handler_processor.rb,
lib/railbox/workers/process_queue_worker.rb,
lib/generators/railbox/install/install_generator.rb,
lib/railbox/mutators/transactional_outbox_mutator.rb,
lib/railbox/interfaces/transactional_outbox_interface.rb

Overview

Module to be included in service classes for adding queue processing support and an additional outbox_entity property.

Examples:

Usage

class MyService
  include Railbox::Handler
end

MyService.enqueue(method: 'update', body: { key: 'value' })

Defined Under Namespace

Modules: Exceptions, Generators, Handler, HttpClient, Models, Mutators, Processors, Queue, Workers Classes: Configuration, TransactionalOutboxInterface

Constant Summary collapse

HttpQueue =
Railbox::Queue::HttpQueue
HandlingQueue =
Railbox::Queue::HandlingQueue
TransactionalOutbox =
Railbox::Models::TransactionalOutbox
TransactionalOutboxMutator =
Railbox::Mutators::TransactionalOutboxMutator
QueueError =
Railbox::Exceptions::QueueError
ValidationError =
Railbox::Exceptions::ValidationError

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject



38
39
40
# File 'lib/railbox.rb', line 38

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



33
34
35
36
# File 'lib/railbox.rb', line 33

def configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

Instance Method Details

#outbox_entityObject

Returns the current value of outbox_entity.

Returns:

  • (Object)

    Returns the current value of outbox_entity.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/railbox/handler/handler.rb', line 14

module Railbox
  module Handler
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      attr_accessor :outbox_entity

      # Queues a request for asynchronous execution
      # @param method [String] to be called (default: 'create')
      # @param body [Hash] main payload for the handler
      # @param opts [Hash] any additional options (e.g. relative_entity/meta)
      #
      def enqueue(method: 'create', body: {}, **opts)
        HandlingQueue.enqueue(service: name, method: method, body: body, **opts)
      end

      # Base failure hook:
      # - can be safely called even if not overridden in the service;
      # - does nothing by default;
      # - when overridden, has access to `outbox_entity`.
      def on_failure
        # no-op by default
      end
    end
  end
end