New returns a new Checker that periodically checks for Coder updates.
(db database.Store, log slog.Logger, opts Options)
| 59 | |
| 60 | // New returns a new Checker that periodically checks for Coder updates. |
| 61 | func New(db database.Store, log slog.Logger, opts Options) *Checker { |
| 62 | if opts.Client == nil { |
| 63 | opts.Client = http.DefaultClient |
| 64 | } |
| 65 | if opts.URL == "" { |
| 66 | opts.URL = defaultURL |
| 67 | } |
| 68 | if opts.Interval == 0 { |
| 69 | opts.Interval = 24 * time.Hour |
| 70 | } |
| 71 | if opts.UpdateTimeout == 0 { |
| 72 | opts.UpdateTimeout = 30 * time.Second |
| 73 | } |
| 74 | if opts.Notify == nil { |
| 75 | opts.Notify = func(_ Result) {} |
| 76 | } |
| 77 | |
| 78 | ctx, cancel := context.WithCancel(context.Background()) |
| 79 | c := &Checker{ |
| 80 | ctx: ctx, |
| 81 | cancel: cancel, |
| 82 | db: db, |
| 83 | log: log, |
| 84 | opts: opts, |
| 85 | firstCheck: make(chan struct{}), |
| 86 | closed: make(chan struct{}), |
| 87 | } |
| 88 | go c.start() |
| 89 | return c |
| 90 | } |
| 91 | |
| 92 | // Result is the result from the last update check. |
| 93 | type Result struct { |