Skip to content

feat(coderd): insert provisioner daemons #11207

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 20 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove need for nil check in heartbeat()
  • Loading branch information
johnstcn committed Dec 18, 2023
commit 9585b75d4bd31ede211af33285eb83b1d34ace21
22 changes: 13 additions & 9 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type Options struct {

// HeartbeatFn is the function that will be called at the interval
// specified by HeartbeatInterval.
// This is only used in tests.
// The default function just calls UpdateProvisionerDaemonLastSeenAt.
// This is mainly used for testing.
HeartbeatFn func(context.Context) error
}

Expand Down Expand Up @@ -182,6 +183,16 @@ func NewServer(
if options.HeartbeatInterval == 0 {
options.HeartbeatInterval = DefaultHeartbeatInterval
}
// Avoid a nil check in s.heartbeat.
if options.HeartbeatFn == nil {
options.HeartbeatFn = func(hbCtx context.Context) error {
//nolint:gocritic // This is specifically for updating the last seen at timestamp.
return db.UpdateProvisionerDaemonLastSeenAt(dbauthz.AsSystemRestricted(hbCtx), database.UpdateProvisionerDaemonLastSeenAtParams{
ID: id,
LastSeenAt: sql.NullTime{Time: time.Now(), Valid: true},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this was s.timeNow(), but turned into time.Now(). I suppose that's OK? Should it be dbtime.Now(), though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be s.timeNow, will hotfix 👍 Thanks for the catch

})
}
}

s := &server{
lifecycleCtx: lifecycleCtx,
Expand Down Expand Up @@ -261,14 +272,7 @@ func (s *server) heartbeat(ctx context.Context) error {
case <-ctx.Done():
return nil
default:
if s.heartbeatFn != nil {
return s.heartbeatFn(ctx)
}
//nolint:gocritic // This is specifically for updating the last seen at timestamp.
return s.Database.UpdateProvisionerDaemonLastSeenAt(dbauthz.AsSystemRestricted(ctx), database.UpdateProvisionerDaemonLastSeenAtParams{
ID: s.ID,
LastSeenAt: sql.NullTime{Time: s.timeNow(), Valid: true},
})
return s.heartbeatFn(ctx)
}
}

Expand Down