handleWaitCommand implements /wait …
(ctx context.Context, input string)
| 76 | |
| 77 | // handleWaitCommand implements /wait … |
| 78 | func (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)) |
no test coverage detected