Prevent Starting Task Twice
This commit is contained in:
parent
b99a818040
commit
c37c26908d
2 changed files with 6 additions and 0 deletions
|
@ -3,3 +3,4 @@ package constants
|
|||
import "fmt"
|
||||
|
||||
var ErrTaskDoesNotExist = fmt.Errorf("Task does not Exist")
|
||||
var ErrTaskIsAlreadyRunning = fmt.Errorf("Task is Already Running")
|
||||
|
|
|
@ -17,6 +17,11 @@ func StartTask(conf config.Config, data types.TaskStart) error {
|
|||
taskMutex.Lock()
|
||||
defer taskMutex.Unlock()
|
||||
|
||||
_, ok := tasks[data.ID]
|
||||
if ok {
|
||||
return constants.ErrTaskIsAlreadyRunning
|
||||
}
|
||||
|
||||
tasks[data.ID] = &types.Task{
|
||||
ID: data.ID,
|
||||
Type: data.Type,
|
||||
|
|
Loading…
Add table
Reference in a new issue