(c *gin.Context, name string, resources []string, proc task.Process)
| 195 | } |
| 196 | |
| 197 | func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, proc task.Process) { |
| 198 | // Run this task in background if configured globally or per-request |
| 199 | background := truthy(c.DefaultQuery("_async", strconv.FormatBool(context.Config().AsyncAPI))) |
| 200 | if background { |
| 201 | log.Debug().Msg("Executing task asynchronously") |
| 202 | task, conflictErr := runTaskInBackground(name, resources, proc) |
| 203 | if conflictErr != nil { |
| 204 | AbortWithJSONError(c, 409, conflictErr) |
| 205 | return |
| 206 | } |
| 207 | c.JSON(202, task) |
| 208 | } else { |
| 209 | log.Debug().Msg("Executing task synchronously") |
| 210 | task, conflictErr := runTaskInBackground(name, resources, proc) |
| 211 | if conflictErr != nil { |
| 212 | AbortWithJSONError(c, 409, conflictErr) |
| 213 | return |
| 214 | } |
| 215 | |
| 216 | // wait for task to finish |
| 217 | _, _ = context.TaskList().WaitForTaskByID(task.ID) |
| 218 | |
| 219 | retValue, _ := context.TaskList().GetTaskReturnValueByID(task.ID) |
| 220 | err, _ := context.TaskList().GetTaskErrorByID(task.ID) |
| 221 | _, _ = context.TaskList().DeleteTaskByID(task.ID) |
| 222 | if err != nil { |
| 223 | AbortWithJSONError(c, retValue.Code, err) |
| 224 | return |
| 225 | } |
| 226 | if retValue != nil { |
| 227 | c.JSON(retValue.Code, retValue.Value) |
| 228 | } else { |
| 229 | c.JSON(http.StatusOK, nil) |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // Common piece of code to show list of packages, |
| 235 | // with searching & details if requested |
no test coverage detected