MCPcopy Index your code
hub / github.com/coder/coder / sendHeartbeat

Method sendHeartbeat

provisionerd/runner/runner.go:328–350  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

326}
327
328func (r *Runner) sendHeartbeat(ctx context.Context) (*proto.UpdateJobResponse, error) {
329 ctx, span := r.startTrace(ctx, "updateHeartbeat")
330 defer span.End()
331
332 r.mutex.Lock()
333 if !r.okToSend {
334 r.mutex.Unlock()
335 return nil, errUpdateSkipped
336 }
337 r.mutex.Unlock()
338
339 // Skip sending a heartbeat if we've sent an update recently.
340 if lastUpdate := r.lastUpdate.Load(); lastUpdate != nil {
341 if time.Since(*lastUpdate) < r.updateInterval {
342 span.SetAttributes(attribute.Bool("heartbeat_skipped", true))
343 return &proto.UpdateJobResponse{}, nil
344 }
345 }
346
347 return r.update(ctx, &proto.UpdateJobRequest{
348 JobId: r.job.JobId,
349 })
350}
351
352func (r *Runner) update(ctx context.Context, u *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
353 ctx, cancel := context.WithTimeout(ctx, 30*time.Second)

Callers 1

heartbeatRoutineMethod · 0.95

Calls 5

startTraceMethod · 0.95
updateMethod · 0.95
LockMethod · 0.45
UnlockMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected