Class: Events::Subscribers::AgentDispatcher

Inherits:
Object
  • Object
show all
Includes:
Events::Subscriber
Defined in:
lib/events/subscribers/agent_dispatcher.rb

Overview

Reacts to non-pending UserMessage emissions by scheduling AgentRequestJob. This is the event-driven bridge between the channel (which emits the intent) and the job (which persists and delivers the message).

Pending messages are skipped — they are picked up by the running agent loop after it finishes the current turn.

Instance Method Summary collapse

Instance Method Details

#emit(event) ⇒ Object

Parameters:

  • event (Hash)

    Rails.event notification hash



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/events/subscribers/agent_dispatcher.rb', line 16

def emit(event)
  payload = event[:payload]
  return unless payload.is_a?(Hash)
  return unless payload[:type] == "user_message"
  return if payload[:status] == Event::PENDING_STATUS

  session_id = payload[:session_id]
  return unless session_id

  AgentRequestJob.perform_later(session_id, content: payload[:content])
end