Prevent Starting Task Twice

This commit is contained in:
Samuel Lorch 2024-07-06 03:07:06 +02:00
parent b99a818040
commit c37c26908d
2 changed files with 6 additions and 0 deletions

View file

@ -3,3 +3,4 @@ package constants
import "fmt"
var ErrTaskDoesNotExist = fmt.Errorf("Task does not Exist")
var ErrTaskIsAlreadyRunning = fmt.Errorf("Task is Already Running")

View file

@ -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,