fix: wire up agent state change events to event bus
SetOnStateChange was defined but never called. Now agents publish
state changes to 'session.{sid}.agent.{aid}.state' which eventwait
can receive.
This commit is contained in:
parent
f21cd99845
commit
e1b732f09a
|
|
@ -17,6 +17,13 @@ import (
|
|||
"ollie/toolsrv"
|
||||
)
|
||||
|
||||
// wireAgentStateEvents sets up the agent to publish state change events to the event bus.
|
||||
func wireAgentStateEvents(sessID string, ag *agent.Agent) {
|
||||
ag.SetOnStateChange(func(agentID, state string) {
|
||||
session.PublishEvent("session."+sessID+".agent."+agentID+".state", state)
|
||||
})
|
||||
}
|
||||
|
||||
func readBackends(_ HandlerCtx) ([]byte, error) {
|
||||
return []byte(strings.Join(backend.Backends(), "\n") + "\n"), nil
|
||||
}
|
||||
|
|
@ -397,6 +404,7 @@ func requestAgentNew(ctx HandlerCtx, data []byte) ([]byte, error) {
|
|||
al := NewAgentLog("")
|
||||
ctx.Session.SetAgentLog(ag.ID(), al)
|
||||
ag.SetOutput(NewEventHandler(al))
|
||||
wireAgentStateEvents(ctx.Session.ID(), ag)
|
||||
return []byte(ag.ID() + "\n"), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ func NewRoot(cfg Config) *Tree {
|
|||
// Wire up the event handler so agent events flow to the AgentLog
|
||||
if ag := r.Session.FindAgent(ra.ID); ag != nil {
|
||||
ag.SetOutput(NewEventHandler(al))
|
||||
wireAgentStateEvents(r.Session.ID(), ag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue