hourly sync scheduling
This commit is contained in:
parent
e0911df455
commit
880dbf78b0
1 changed files with 22 additions and 0 deletions
22
main.go
22
main.go
|
|
@ -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()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue