feat: refresh accounts automatically every five minutes
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user