X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/a5c83e92d7feea2e104b5515043a76c8c4c56c60..f5c601f1801aaa276f8c335fcb51c373edc0b50c:/daemon_message.go?ds=inline diff --git a/daemon_message.go b/daemon_message.go index 8ee26e8..b70947d 100644 --- a/daemon_message.go +++ b/daemon_message.go @@ -12,6 +12,43 @@ import ( "sync" ) +// DaemonMessages owns the durable queue between the root and its children and +// the routed inputs. The mutex serializes queue writes and delivery. Backups +// take it before the locks of the loops, memory, and subagents. A stored log ID +// makes delivery idempotent, including a stop between the log append and the +// wake. +type DaemonMessages struct { + mutex sync.Mutex + path string + loops map[string]*TurnLoop + ordered []*TurnLoop + state DaemonMessageFile + failure error + routes *Routes +} + +// DaemonMessageFile holds the sequence, unacknowledged deliveries, and receipts +// for WhatsApp batches until the inbox removes them. A receipt stays when its +// turn finishes before inbox removal. +type DaemonMessageFile struct { + Next int `json:"next"` + Pending []DaemonMessage `json:"pending"` + WhatsAppBatches []int `json:"whatsapp_batches,omitempty"` +} + +// DaemonMessage is one queued delivery. LogID is set before the log append. A +// nil LogID means that delivery has not started. WhatsAppBatch marks a routed +// external batch, whose event source is WhatsApp rather than its queue sender. +type DaemonMessage struct { + ID int `json:"id"` + Source string `json:"source"` + Target string `json:"target"` + Kind string `json:"kind"` + Text string `json:"text"` + LogID *int `json:"log_id,omitempty"` + WhatsAppBatch int `json:"whatsapp_batch,omitempty"` +} + // openDaemonMessages connects the root and its children. It restores queued // messages before the loops start. A queue entry stays until its recipient // finishes the turn that takes it, so a stop can interrupt delivery or a turn. @@ -109,21 +146,6 @@ func openDaemonMessages(loops []*TurnLoop) (*DaemonMessages, error) { return m, nil } -// DaemonMessages owns the durable queue between the root and its children and -// the routed inputs. The mutex serializes queue writes and delivery. Backups -// take it before the locks of the loops, memory, and subagents. A stored log ID -// makes delivery idempotent, including a stop between the log append and the -// wake. -type DaemonMessages struct { - mutex sync.Mutex - path string - loops map[string]*TurnLoop - ordered []*TurnLoop - state DaemonMessageFile - failure error - routes *Routes -} - // deliver records one queued message and wakes its recipient. The caller holds // the mutex, or owns the queue before the loops start. func (m *DaemonMessages) deliver(message *DaemonMessage) error { @@ -441,25 +463,3 @@ func (m *DaemonMessages) Finish(loop *TurnLoop, active []Message, reply string) return nil } - -// DaemonMessageFile holds the sequence, unacknowledged deliveries, and receipts -// for WhatsApp batches until the inbox removes them. A receipt stays when its -// turn finishes before inbox removal. -type DaemonMessageFile struct { - Next int `json:"next"` - Pending []DaemonMessage `json:"pending"` - WhatsAppBatches []int `json:"whatsapp_batches,omitempty"` -} - -// DaemonMessage is one queued delivery. LogID is set before the log append. A -// nil LogID means that delivery has not started. WhatsAppBatch marks a routed -// external batch, whose event source is WhatsApp rather than its queue sender. -type DaemonMessage struct { - ID int `json:"id"` - Source string `json:"source"` - Target string `json:"target"` - Kind string `json:"kind"` - Text string `json:"text"` - LogID *int `json:"log_id,omitempty"` - WhatsAppBatch int `json:"whatsapp_batch,omitempty"` -}