mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-18 18:15:21 +00:00
fix(channels): start outbound dispatcher before channel check (#15)
StartAll() returned early when no channels existed at boot, skipping the dispatchOutbound goroutine. Channels loaded later via Reload() assumed the dispatcher was running, causing outbound messages (agent responses) to never reach Telegram. Move dispatcher startup before the empty-channel early return so dynamically loaded channels always have a running consumer. Co-authored-by: ntduc <ntduc@cpp.ai.vn>
This commit is contained in:
1 parent
4db5259581
commit
fcaf3531ba
1 file changed
+7
-5
@@ -45,10 +45,17 @@ func NewManager(msgBus *bus.MessageBus) *Manager {
|
||||
}
|
||||
|
||||
// StartAll starts all registered channels and the outbound dispatch loop.
|
||||
// The dispatcher is always started even when no channels exist yet,
|
||||
// because channels may be loaded dynamically later via Reload().
|
||||
func (m *Manager) StartAll(ctx context.Context) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
// Always start the outbound dispatcher — channels may be added later via Reload().
|
||||
dispatchCtx, cancel := context.WithCancel(ctx)
|
||||
m.dispatchTask = &asyncTask{cancel: cancel}
|
||||
go m.dispatchOutbound(dispatchCtx)
|
||||
|
||||
if len(m.channels) == 0 {
|
||||
slog.Warn("no channels enabled")
|
||||
return nil
|
||||
@@ -56,11 +63,6 @@ func (m *Manager) StartAll(ctx context.Context) error {
|
||||
|
||||
slog.Info("starting all channels")
|
||||
|
||||
dispatchCtx, cancel := context.WithCancel(ctx)
|
||||
m.dispatchTask = &asyncTask{cancel: cancel}
|
||||
|
||||
go m.dispatchOutbound(dispatchCtx)
|
||||
|
||||
for name, channel := range m.channels {
|
||||
slog.Info("starting channel", "channel", name)
|
||||
if err := channel.Start(ctx); err != nil {
|
||||
|
||||
Reference in new issue
Block a user