MCPcopy Create free account
hub / github.com/cli/cli / heartbeat

Method heartbeat

internal/codespaces/rpc/invoker.go:277–298  ·  view source on GitHub ↗

Periodically check whether there is a reason to keep the connection alive, and if so, notify the codespace to do so

(ctx context.Context, interval time.Duration)

Source from the content-addressed store, hash-verified

275
276// Periodically check whether there is a reason to keep the connection alive, and if so, notify the codespace to do so
277func (i *invoker) heartbeat(ctx context.Context, interval time.Duration) {
278 ticker := time.NewTicker(interval)
279 defer ticker.Stop()
280
281 for {
282 select {
283 case <-ctx.Done():
284 return
285 case <-ticker.C:
286 reason := ""
287
288 // If the keep alive override flag is set, we don't need to check for activity on the forwarder
289 // Otherwise, grab the reason from the forwarder
290 if i.keepAliveOverride {
291 reason = keepAliveEventName
292 } else {
293 reason = i.fwd.GetKeepAliveReason()
294 }
295 _ = i.notifyCodespaceOfClientActivity(ctx, reason)
296 }
297 }
298}
299
300func (i *invoker) notifyCodespaceOfClientActivity(ctx context.Context, activity string) error {
301 ctx = i.appendMetadata(ctx)

Callers 1

connectFunction · 0.95

Calls 3

DoneMethod · 0.65
GetKeepAliveReasonMethod · 0.65

Tested by

no test coverage detected