Add event-driven daemon architecture (Phase 1 foundation)
- Add fsnotify dependency for file watching - Create daemon_debouncer.go: batch rapid events (500ms window) - Create daemon_watcher.go: monitor JSONL and git refs changes - Create daemon_event_loop.go: event-driven sync loop - Add mutation channel to RPC server (create/update/close events) - Add BEADS_DAEMON_MODE env var (poll/events, default: poll) Phase 1 implementation: opt-in via BEADS_DAEMON_MODE=events Target: <500ms latency (vs 5000ms), ~60% CPU reduction Related: bd-49 (epic), bd-50, bd-51, bd-53, bd-54, bd-55, bd-56 Amp-Thread-ID: https://ampcode.com/threads/T-35a3d0d7-4e19-421d-8392-63755035036e Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -1299,5 +1299,30 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush bool, logPath, p
|
||||
doSync := createSyncFunc(ctx, store, autoCommit, autoPush, log)
|
||||
doSync()
|
||||
|
||||
runEventLoop(ctx, cancel, ticker, doSync, server, serverErrChan, log)
|
||||
// Choose event loop based on BEADS_DAEMON_MODE
|
||||
daemonMode := os.Getenv("BEADS_DAEMON_MODE")
|
||||
if daemonMode == "" {
|
||||
daemonMode = "poll" // Default to polling for Phase 1
|
||||
}
|
||||
|
||||
switch daemonMode {
|
||||
case "events":
|
||||
log.log("Using event-driven mode")
|
||||
// For Phase 1: event-driven mode uses full sync on both export and import events
|
||||
// TODO: Optimize to separate export-only and import-only triggers
|
||||
jsonlPath := findJSONLPath()
|
||||
if jsonlPath == "" {
|
||||
log.log("Error: JSONL path not found, cannot use event-driven mode")
|
||||
log.log("Falling back to polling mode")
|
||||
runEventLoop(ctx, cancel, ticker, doSync, server, serverErrChan, log)
|
||||
} else {
|
||||
runEventDrivenLoop(ctx, cancel, server, serverErrChan, store, jsonlPath, doSync, doSync, log)
|
||||
}
|
||||
case "poll":
|
||||
log.log("Using polling mode (interval: %v)", interval)
|
||||
runEventLoop(ctx, cancel, ticker, doSync, server, serverErrChan, log)
|
||||
default:
|
||||
log.log("Unknown BEADS_DAEMON_MODE: %s (valid: poll, events), defaulting to poll", daemonMode)
|
||||
runEventLoop(ctx, cancel, ticker, doSync, server, serverErrChan, log)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user