queue sync calls

This commit is contained in:
André Roth
2024-06-08 12:27:59 +02:00
parent efc5573b8e
commit 3e1485faf5
3 changed files with 24 additions and 3 deletions

View File

@@ -164,9 +164,17 @@ func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, p
c.JSON(202, task)
} else {
log.Debug().Msg("Executing task synchronously")
out := context.Progress()
detail := task.Detail{}
retValue, err := proc(out, &detail)
task, conflictErr := runTaskInBackground(name, resources, proc)
if conflictErr != nil {
AbortWithJSONError(c, 409, conflictErr)
return
}
// wait for task to finish
context.TaskList().WaitForTaskByID(task.ID)
retValue, _ := context.TaskList().GetTaskReturnValueByID(task.ID)
err, _ := context.TaskList().GetTaskErrorByID(task.ID)
if err != nil {
AbortWithJSONError(c, retValue.Code, err)
return

View File

@@ -56,6 +56,7 @@ func (list *List) consumer() {
list.Lock()
{
task.processReturnValue = retValue
task.err = err
if err != nil {
task.output.Printf("Task failed with error: %v", err)
task.State = FAILED
@@ -241,3 +242,14 @@ func (list *List) WaitForTaskByID(ID int) (Task, error) {
wgTask.Wait()
return list.GetTaskByID(ID)
}
// GetTaskError returns the Task error for a given id
func (list *List) GetTaskErrorByID(ID int) (error, error) {
task, err := list.GetTaskByID(ID)
if err != nil {
return nil, err
}
return task.err, nil
}

View File

@@ -47,6 +47,7 @@ type Task struct {
detail *Detail
process Process
processReturnValue *ProcessReturnValue
err error
Name string
ID int
State State