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