Documentation
¶
Overview ¶
Package realtime provides an audit-log ("outbox") for realtime events broadcast via PocketBase's SSE mechanism, plus a small helper API used by other packages (e.g. the stuck-operation reaper) to record synthetic events that did not originate from a record CRUD call.
Motivation ¶
PocketBase's built-in realtime publish path is fire-and-forget: the event is handed to each subscriber's buffered channel in a goroutine; there is no persistence, no retry, no delivery ACK. When an agent's SSE connection is briefly interrupted — a common occurrence on flaky networks — the message is lost with zero trace on the server, which is exactly the "black hole" the user asked us to address.
This package does NOT replace PocketBase's realtime broadcaster. Instead it writes a row to the `realtime_messages` collection every time one of the tracked operation records (patch_operations, reboot_operations, investigations) is created or updated, giving us a durable audit trail that operators can query to answer "did the server attempt to tell the agent?" The actual SSE broadcast still happens via PocketBase's OnModelAfterCreateSuccess/UpdateSuccess hooks.
Index ¶
Constants ¶
const ( ResourcePatchOperations = "patch_operations" ResourceRebootOperations = "reboot_operations" ResourceInvestigations = "investigations" )
Tracked resource (collection) names.
const ( DeliveryLogged = "logged" // standard CRUD-derived event DeliveryReaperFailed = "reaper_failed" // synthetic event emitted by the reaper )
Delivery statuses recorded in the outbox.
Variables ¶
This section is empty.
Functions ¶
func LogEvent ¶
func LogEvent( app core.App, resourceType string, resourceID string, action string, agentID string, userID string, resourceStatus string, deliveryStatus string, payload map[string]any, errMsg string, )
LogEvent persists a single outbox entry. Errors are logged but never returned to the caller so that an outbox failure can never break the originating write path.
func RegisterOutboxHooks ¶
RegisterOutboxHooks binds after-create and after-update hooks for the tracked collections so that every change is mirrored into the outbox. Safe to call once on application startup.
Types ¶
This section is empty.