Module: Legion::API::SyncDispatch

Defined in:
lib/legion/api/sync_dispatch.rb

Class Method Summary collapse

Class Method Details

.dispatch(exchange_name, routing_key, payload, envelope, timeout: 30) ⇒ Hash

Dispatch a message synchronously via AMQP using a temporary reply_to queue. Blocks until a response arrives or the timeout expires.

Parameters:

  • exchange_name (String)

    target exchange (e.g. “lex.github”)

  • routing_key (String)

    routing key (e.g. “lex.github.runners.pull_request.create”)

  • payload (Hash)

    message payload

  • envelope (Hash)

    task envelope (task_id, conversation_id, etc.)

  • timeout (Integer) (defaults to: 30)

    seconds to wait (default 30)

Returns:

  • (Hash)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/legion/api/sync_dispatch.rb', line 17

def self.dispatch(exchange_name, routing_key, payload, envelope, timeout: 30)
  unless defined?(Legion::Transport) &&
         Legion::Transport.respond_to?(:connected?) &&
         Legion::Transport.connected?
    return envelope.merge(
      status: 'failed',
      error:  { code: 503, message: 'Transport not available for sync dispatch' }
    )
  end

  perform_dispatch(exchange_name, routing_key, payload, envelope, timeout)
rescue StandardError => e
  Legion::Logging.error "[SyncDispatch] #{e.class}: #{e.message}" if defined?(Legion::Logging)
  envelope.merge(
    status: 'failed',
    error:  { code: 500, message: e.message }
  )
end