MCPcopy Index your code
hub / github.com/coder/coder / startAgentAPI

Method startAgentAPI

agent/agent.go:2443–2467  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

2441// startAgentAPI starts a routine that uses the Agent API. c.f. startTailnetAPI which is the same
2442// but for Tailnet.
2443func (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.

Callers 1

runMethod · 0.80

Calls 4

shouldPropagateErrorFunction · 0.85
GoMethod · 0.80
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected