MCPcopy Create free account
hub / github.com/compozy/agh / waitForDaemonStop

Function waitForDaemonStop

internal/cli/daemon.go:243–280  ·  view source on GitHub ↗
(
	ctx context.Context,
	deps commandDeps,
	runtime *runtimeContext,
	info aghdaemon.Info,
)

Source from the content-addressed store, hash-verified

241}
242
243func waitForDaemonStop(
244 ctx context.Context,
245 deps commandDeps,
246 runtime *runtimeContext,
247 info aghdaemon.Info,
248) (DaemonStatus, error) {
249 waitCtx := ctx
250 if waitCtx == nil {
251 waitCtx = context.Background()
252 }
253 if _, hasDeadline := waitCtx.Deadline(); !hasDeadline {
254 var cancel context.CancelFunc
255 waitCtx, cancel = context.WithTimeout(waitCtx, deps.stopTimeout)
256 defer cancel()
257 }
258
259 client, clientErr := clientFromDeps(deps)
260 ticker := time.NewTicker(deps.pollInterval)
261 defer ticker.Stop()
262
263 for {
264 select {
265 case <-waitCtx.Done():
266 return DaemonStatus{}, errors.New("cli: daemon did not stop before timeout")
267 case <-ticker.C:
268 if _, running, err := daemonInfo(runtime.HomePaths, deps); err == nil && !running {
269 return daemonStatusWithState(runtime, info, "stopped"), nil
270 }
271 if clientErr == nil {
272 if _, err := client.DaemonStatus(waitCtx); err != nil {
273 if _, running, infoErr := daemonInfo(runtime.HomePaths, deps); infoErr == nil && !running {
274 return daemonStatusWithState(runtime, info, "stopped"), nil
275 }
276 }
277 }
278 }
279 }
280}
281
282func daemonStatusFromDeps(ctx context.Context, deps commandDeps, runtime *runtimeContext) (DaemonStatus, error) {
283 client, err := clientFromDeps(deps)

Calls 6

clientFromDepsFunction · 0.85
daemonInfoFunction · 0.85
daemonStatusWithStateFunction · 0.85
StopMethod · 0.65
DoneMethod · 0.65
DaemonStatusMethod · 0.65