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