MCPcopy Index your code
hub / github.com/aptly-dev/aptly / maybeRunTaskInBackground

Function maybeRunTaskInBackground

api/api.go:197–232  ·  view source on GitHub ↗
(c *gin.Context, name string, resources []string, proc task.Process)

Source from the content-addressed store, hash-verified

195}
196
197func 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

Callers 15

apiReposCreateFunction · 0.85
apiReposEditFunction · 0.85
apiReposDropFunction · 0.85
apiReposPackageFromDirFunction · 0.85
apiReposCopyPackageFunction · 0.85
apiMirrorsDropFunction · 0.85
apiMirrorsUpdateFunction · 0.85
apiDBCleanupFunction · 0.85
apiSnapshotsCreateFunction · 0.85

Calls 9

truthyFunction · 0.85
runTaskInBackgroundFunction · 0.85
AbortWithJSONErrorFunction · 0.85
ConfigMethod · 0.80
WaitForTaskByIDMethod · 0.80
TaskListMethod · 0.80
GetTaskErrorByIDMethod · 0.80
DeleteTaskByIDMethod · 0.80

Tested by

no test coverage detected