MCPcopy Create free account
hub / github.com/QuantumNous/new-api / waitTaskPluginImageTask

Function waitTaskPluginImageTask

controller/plugin_protocol_image.go:189–211  ·  view source on GitHub ↗

waitTaskPluginImageTask polls an asynchronous image task inside the client request through the ordinary task polling path, so completion settles billing exactly as the background poller would, until the task is terminal or the protocol timeout elapses. A client disconnect stops waiting; the backgrou

(c *gin.Context, task *model.Task, deps pluginProtocolBridgeDeps)

Source from the content-addressed store, hash-verified

187// or the protocol timeout elapses. A client disconnect stops waiting; the
188// background poller then finishes the durable task.
189func waitTaskPluginImageTask(c *gin.Context, task *model.Task, deps pluginProtocolBridgeDeps) *dto.TaskError {
190 ctx, cancel := context.WithTimeout(c.Request.Context(), deps.submissionTimeout)
191 defer cancel()
192 for {
193 timer := time.NewTimer(deps.imagePollInterval)
194 select {
195 case <-ctx.Done():
196 timer.Stop()
197 if errors.Is(ctx.Err(), context.DeadlineExceeded) && c.Request.Context().Err() == nil {
198 return service.TaskErrorWrapperLocal(fmt.Errorf("image generation is still running; task %s settles when it completes", task.TaskID), "task_timeout", http.StatusGatewayTimeout)
199 }
200 return service.TaskErrorWrapperLocal(ctx.Err(), "request_cancelled", http.StatusRequestTimeout)
201 case <-timer.C:
202 }
203 if err := deps.pollTask(ctx, task); err != nil {
204 logger.LogWarn(c, common.LogText("task protocol image poll failed for task %s: %s", task.TaskID, common.MaskSensitiveInfo(err.Error(), common.UpstreamAddresses(c)...)))
205 continue
206 }
207 if task.Status == model.TaskStatusSuccess || task.Status == model.TaskStatusFailure {
208 return nil
209 }
210 }
211}
212
213// pollTaskPluginImageTask runs one poll round for a single task through the
214// same code path as the scheduled task poller, including status CAS and

Callers 1

Calls 6

TaskErrorWrapperLocalFunction · 0.92
LogWarnFunction · 0.92
StopMethod · 0.80
cancelFunction · 0.50
DoneMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected