feat: Phase 2.7+3 — full integration, config update, systemd unit
- Wire all goroutines in main.go: watcher, quota monitor, account switcher, dispatcher, janitor, and 10s state flush loop - Add missing sections to config.example.yaml: notifications, dispatcher, watcher, janitor - Add scripts/claude-failover.service systemd unit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d4260f71b4
commit
28f82a66c8
5 changed files with 390 additions and 1 deletions
|
|
@ -8,12 +8,19 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/api"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/config"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/dispatcher"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/janitor"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/lifecycle"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/notify"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/quota"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/state"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/switcher"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/tmux"
|
||||
"forge.secuaas.ovh/olivier/claude-failover/internal/watcher"
|
||||
)
|
||||
|
||||
const version = "0.1.0"
|
||||
|
|
@ -53,6 +60,43 @@ func main() {
|
|||
|
||||
go lm.Run(ctx)
|
||||
|
||||
// Notifier — reads credentials from environment variables.
|
||||
notifier := notify.New(cfg)
|
||||
|
||||
// Session Watcher — detects when sessions finish their tasks.
|
||||
sw := watcher.New(tmuxClient, s, cfg)
|
||||
go sw.Run(ctx)
|
||||
|
||||
// Quota Monitor — polls panes for quota exhaustion signals.
|
||||
qm := quota.New(tmuxClient, s, cfg)
|
||||
go qm.Run(ctx)
|
||||
|
||||
// Account Switcher — orchestrates account failover on quota exhaustion.
|
||||
as := switcher.New(tmuxClient, s, cfg, qm.SwitchChan(), notifier)
|
||||
go as.Run(ctx)
|
||||
|
||||
// Dispatcher — assigns inbox tasks to idle sessions.
|
||||
disp := dispatcher.New(tmuxClient, s, cfg, sw.DoneChan())
|
||||
go disp.Run(ctx)
|
||||
|
||||
// Janitor — periodic cleanup of orphaned files and stale status.json.
|
||||
jan := janitor.New(s, cfg.Dispatcher.ProjectsDir)
|
||||
go jan.Run(ctx)
|
||||
|
||||
// State flush loop — persists state to disk every 10 seconds.
|
||||
go func() {
|
||||
ticker := time.NewTicker(10 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
s.Flush() //nolint:errcheck
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Start HTTP API server.
|
||||
listenAddr := cfg.MCPHTTP.Listen
|
||||
if listenAddr == "" {
|
||||
|
|
@ -65,7 +109,8 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
log.Printf("claude-failover v%s started, API on %s", version, listenAddr)
|
||||
|
||||
log.Printf("claude-failover v%s — all goroutines running", version)
|
||||
|
||||
<-ctx.Done()
|
||||
log.Printf("shutdown signal received — flushing state and exiting")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue