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)
| 275 | |
| 276 | // Periodically check whether there is a reason to keep the connection alive, and if so, notify the codespace to do so |
| 277 | func (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 | |
| 300 | func (i *invoker) notifyCodespaceOfClientActivity(ctx context.Context, activity string) error { |
| 301 | ctx = i.appendMetadata(ctx) |
no test coverage detected