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

Method heartbeat

internal/codespaces/rpc/invoker.go:272–293  ·  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

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

Callers 1

connectFunction · 0.95

Calls 3

DoneMethod · 0.65
GetKeepAliveReasonMethod · 0.65

Tested by

no test coverage detected