feat: refresh accounts automatically every five minutes

This commit is contained in:
2026-08-14 15:35:27 +08:00
parent c1985852e1
commit 5f50669b98
11 changed files with 66 additions and 145 deletions
+9 -6
View File
@@ -52,6 +52,8 @@ type accountRuntime struct {
stopped bool
}
const automaticSyncInterval = time.Duration(automaticSyncMinutes) * time.Minute
type codexClient interface {
Start(context.Context) error
Initialize(context.Context) error
@@ -267,17 +269,18 @@ func (a *App) syncAll(ctx context.Context) {
}
}
func (a *App) scheduler() {
t := time.NewTicker(time.Minute)
defer t.Stop()
maintenanceTicker := time.NewTicker(time.Minute)
syncTicker := time.NewTicker(automaticSyncInterval)
defer maintenanceTicker.Stop()
defer syncTicker.Stop()
for {
select {
case <-a.ctx.Done():
return
case <-t.C:
case <-syncTicker.C:
a.syncAll(context.Background())
case <-maintenanceTicker.C:
g := a.general()
if time.Now().Unix()%(int64(g.SyncMinutes)*60) < 60 {
a.syncAll(context.Background())
}
_, _ = a.store.Cleanup(g.RetentionDays)
go a.processReminders()
}