MCPcopy Create free account
hub / github.com/diillson/chatcli / handleWaitCommand

Method handleWaitCommand

cli/scheduler_command.go:78–137  ·  view source on GitHub ↗

handleWaitCommand implements /wait …

(ctx context.Context, input string)

Source from the content-addressed store, hash-verified

76
77// handleWaitCommand implements /wait …
78func (cli *ChatCLI) handleWaitCommand(ctx context.Context, input string) {
79 if !cli.schedulerEnabled() {
80 fmt.Println(colorize(" "+i18n.T("scheduler.disabled"), ColorYellow))
81 return
82 }
83 args, err := tokenizeSchedulerInput(strings.TrimPrefix(input, "/wait"))
84 if err != nil {
85 fmt.Println(colorize(" ❌ "+err.Error(), ColorRed))
86 return
87 }
88 if len(args) == 0 || args[0] == "help" {
89 cli.printWaitUsage()
90 return
91 }
92 in, err := parseWaitArgs(args)
93 if err != nil {
94 fmt.Println(colorize(" ❌ "+err.Error(), ColorRed))
95 cli.printWaitUsage()
96 return
97 }
98 owner := cli.currentSchedulerOwner()
99 // Wait blocks by default; use --async to fire-and-forget.
100 ctx, cancel := context.WithTimeout(ctx, 45*time.Minute)
101 defer cancel()
102 if cli.schedulerRemote != nil {
103 out, err := cli.schedulerRemote.Enqueue(ctx, owner, in)
104 if err != nil {
105 fmt.Println(colorize(" ❌ "+err.Error(), ColorRed))
106 return
107 }
108 if !out.OK {
109 fmt.Println(colorize(" ❌ "+out.Error, ColorRed))
110 return
111 }
112 if in.Async {
113 fmt.Println(colorize(" ✔ "+i18n.T("scheduler.wait_async", out.JobID), ColorGreen))
114 return
115 }
116 // Poll for terminal status.
117 waitForTerminal(ctx, cli.schedulerRemote, out.JobID)
118 return
119 }
120 adapter := scheduler.NewToolAdapter(cli.scheduler)
121 raw := mustJSON(in)
122 res, _ := adapter.WaitUntil(ctx, owner, raw)
123 var out scheduler.ToolOutput
124 _ = jsonDecode(res, &out)
125 if !out.OK {
126 fmt.Println(colorize(" ❌ "+out.Error, ColorRed))
127 return
128 }
129 if in.Async {
130 fmt.Println(colorize(" ✔ "+i18n.T("scheduler.wait_async", out.JobID), ColorGreen))
131 return
132 }
133 fmt.Println(colorize(fmt.Sprintf(" ✔ %s", i18n.T("scheduler.wait_completed", out.JobID, string(out.Outcome))), ColorGreen))
134 if out.Details != "" {
135 fmt.Println(colorize(out.Details, ColorGray))

Callers 1

buildRoutesMethod · 0.80

Calls 14

schedulerEnabledMethod · 0.95
printWaitUsageMethod · 0.95
currentSchedulerOwnerMethod · 0.95
WaitUntilMethod · 0.95
TFunction · 0.92
NewToolAdapterFunction · 0.92
colorizeFunction · 0.85
tokenizeSchedulerInputFunction · 0.85
parseWaitArgsFunction · 0.85
waitForTerminalFunction · 0.85
mustJSONFunction · 0.85
jsonDecodeFunction · 0.85

Tested by

no test coverage detected