Skip to content

feat: Add support for update checks and notifications #4810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 1, 2022
Merged
Prev Previous commit
Next Next commit
Fix logging
  • Loading branch information
mafredri committed Nov 29, 2022
commit 0238d5a4a01c7b7f14c3f19bf53456e9a83d6006
38 changes: 17 additions & 21 deletions coderd/updatecheck/updatecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,29 @@ func (c *Checker) start() {
t := time.NewTicker(c.opts.Interval)
defer t.Stop()

doCheck := func() {
rr, err := c.update()
if err != nil {
if xerrors.Is(err, context.Canceled) {
return
}
c.log.Error(c.ctx, "update check failed", slog.Error(err))
} else {
c.notifyIfNewer(r, rr)
r = rr
}
diff := time.Until(r.Checked.Add(c.opts.Interval))
if diff > 0 {
c.log.Info(c.ctx, "time until next update check", slog.F("duration", diff))
t.Reset(diff)
} else {
c.log.Info(c.ctx, "time until next update check", slog.F("duration", c.opts.Interval))
t.Reset(c.opts.Interval)
}

if !r.Checked.IsZero() {
diff := time.Until(r.Checked.Add(c.opts.Interval))
if diff > 0 {
c.log.Info(c.ctx, "time until next update check", slog.F("duration", diff))
t.Reset(diff)
}
}

for {
select {
case <-t.C:
doCheck()
rr, err := c.update()
if err != nil {
if xerrors.Is(err, context.Canceled) {
return
}
c.log.Error(c.ctx, "update check failed", slog.Error(err))
} else {
c.notifyIfNewer(r, rr)
r = rr
}
c.log.Info(c.ctx, "time until next update check", slog.F("duration", c.opts.Interval))
t.Reset(c.opts.Interval)
case <-c.ctx.Done():
return
}
Expand Down