startAgentAPI starts a routine that uses the Agent API. c.f. startTailnetAPI which is the same but for Tailnet.
( name string, behavior gracefulShutdownBehavior, f func(context.Context, proto.DRPCAgentClient28) error, )
| 2441 | // startAgentAPI starts a routine that uses the Agent API. c.f. startTailnetAPI which is the same |
| 2442 | // but for Tailnet. |
| 2443 | func (a *apiConnRoutineManager) startAgentAPI( |
| 2444 | name string, behavior gracefulShutdownBehavior, |
| 2445 | f func(context.Context, proto.DRPCAgentClient28) error, |
| 2446 | ) { |
| 2447 | logger := a.logger.With(slog.F("name", name)) |
| 2448 | var ctx context.Context |
| 2449 | switch behavior { |
| 2450 | case gracefulShutdownBehaviorStop: |
| 2451 | ctx = a.stopCtx |
| 2452 | case gracefulShutdownBehaviorRemain: |
| 2453 | ctx = a.remainCtx |
| 2454 | default: |
| 2455 | panic("unknown behavior") |
| 2456 | } |
| 2457 | a.eg.Go(func() error { |
| 2458 | logger.Debug(ctx, "starting agent routine") |
| 2459 | err := f(ctx, a.aAPI) |
| 2460 | err = shouldPropagateError(ctx, logger, err) |
| 2461 | logger.Debug(ctx, "routine exited", slog.Error(err)) |
| 2462 | if err != nil { |
| 2463 | return xerrors.Errorf("error in routine %s: %w", name, err) |
| 2464 | } |
| 2465 | return nil |
| 2466 | }) |
| 2467 | } |
| 2468 | |
| 2469 | // startTailnetAPI starts a routine that uses the Tailnet API. c.f. startAgentAPI which is the same |
| 2470 | // but for the Agent API. |
no test coverage detected