Skip to content

Commit

Permalink
Wait for cache on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
m110 committed Aug 26, 2024
1 parent acadba7 commit c639b88
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func (c *Cache) Get() Releases {
return c.releases
}

func (c *Cache) Refresh(ctx context.Context) {
func (c *Cache) Refresh() {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

slog.Info("Refreshing cache...")

type result struct {
Expand Down Expand Up @@ -195,13 +198,12 @@ func main() {
}

cache := NewCache(cfg)
cache.Refresh()

go func() {
for {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
cache.Refresh(ctx)
cancel()
time.Sleep(cfg.RefreshInterval)
cache.Refresh()
}
}()

Expand Down

0 comments on commit c639b88

Please sign in to comment.