33 lines
533 B
Go
33 lines
533 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
func (s *Service) StartAutoUpdate(ctx context.Context) {
|
|
go func() {
|
|
cfg, err := s.LoadConfig()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if cfg.Update.CheckOnStartup {
|
|
_ = s.RunAutoUpdate(ctx)
|
|
}
|
|
interval := cfg.Update.IntervalMinutes
|
|
if interval <= 0 {
|
|
interval = 60
|
|
}
|
|
ticker := time.NewTicker(time.Duration(interval) * time.Minute)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
_ = s.RunAutoUpdate(ctx)
|
|
}
|
|
}
|
|
}()
|
|
}
|