hourly sync scheduling

This commit is contained in:
Miloš Jovanović 2026-09-10 12:44:16 +02:00
parent e0911df455
commit 880dbf78b0

22
main.go
View file

@ -5,6 +5,8 @@ import (
"net/http" "net/http"
"strings" "strings"
"os" "os"
"context"
"time"
) )
// ELIGIBLE_APPOINTMENTS is a comma-separated list of appointment type // ELIGIBLE_APPOINTMENTS is a comma-separated list of appointment type
@ -57,6 +59,26 @@ func main() {
} }
srv := NewServer(NewClient(apiKey, dryRun), store, secret, loadEligible()) srv := NewServer(NewClient(apiKey, dryRun), store, secret, loadEligible())
// Prime the cache: a fresh container starts empty.
{
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
if err := srv.SyncRoster(ctx); err != nil {
log.Printf("initial sync failed: %v", err)
}
cancel()
}
go func() {
t := time.NewTicker(time.Hour)
defer t.Stop()
for range t.C {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
if err := srv.SyncRoster(ctx); err != nil {
log.Printf("scheduled sync failed: %v", err)
}
cancel()
}
}()
log.Println("listening on :8080") log.Println("listening on :8080")
log.Fatal(http.ListenAndServe(":8080", srv.Routes())) log.Fatal(http.ListenAndServe(":8080", srv.Routes()))
} }