mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-11 03:11:50 +00:00
api: publish: block on concurrent calls
This commit blocks concurrent calls to RunTaskInBackground which is intended to fix the quirky behaviour where concurrent PUT calls to api/publish/<prefix>/<distribution> would immedietly reuturn an error. The solution proposed in this commit is not elegant and probaly has unintended side-effects. The intention of this commit is to highlight the area that actually needs to be addressed. Ideally this patch is amended or dropped entierly in favor of a better fixup.
This commit is contained in:
committed by
André Roth
parent
47696a3303
commit
1987220f1e
15
task/list.go
15
task/list.go
@@ -117,19 +117,20 @@ func (list *List) GetTaskReturnValueByID(ID int) (*ProcessReturnValue, error) {
|
||||
return task.processReturnValue, nil
|
||||
}
|
||||
|
||||
// RunTaskInBackground creates task and runs it in background. It won't be run and an error
|
||||
// returned if there are running tasks which are using needed resources already.
|
||||
// RunTaskInBackground creates task and runs it in background. This will block until the necessary resources
|
||||
// become available.
|
||||
func (list *List) RunTaskInBackground(name string, resources []string, process Process) (Task, *ResourceConflictError) {
|
||||
list.Lock()
|
||||
defer list.Unlock()
|
||||
|
||||
tasks := list.usedResources.UsedBy(resources)
|
||||
if len(tasks) > 0 {
|
||||
conflictError := &ResourceConflictError{
|
||||
Tasks: tasks,
|
||||
Message: "Needed resources are used by other tasks.",
|
||||
for len(tasks) > 0 {
|
||||
for _, task := range(tasks) {
|
||||
list.Unlock()
|
||||
list.wgTasks[task.ID].Wait()
|
||||
list.Lock()
|
||||
}
|
||||
return Task{}, conflictError
|
||||
tasks = list.usedResources.UsedBy(resources)
|
||||
}
|
||||
|
||||
list.idCounter++
|
||||
|
||||
Reference in New Issue
Block a user