summaryrefslogtreecommitdiffstats
path: root/model/job.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-04-04 11:42:07 -0700
committerHarrison Healey <harrisonmhealey@gmail.com>2017-04-04 14:42:07 -0400
commit6bf080393d88534aa658ecaff32ae089bd304772 (patch)
treebe25ba4cea3d687d11fe49537b84fae4bf21a484 /model/job.go
parent32460bf63bc07c69ee5da0bb5640b879facb5538 (diff)
downloadchat-6bf080393d88534aa658ecaff32ae089bd304772.tar.gz
chat-6bf080393d88534aa658ecaff32ae089bd304772.tar.bz2
chat-6bf080393d88534aa658ecaff32ae089bd304772.zip
Fixing race conditions in the code base (#5966)
* Adding initial race detector * Remove setting of config twice * Fixing config file watch and config reload on license save * Fixing config file watch and config reload on license save * Fixing build error * Fixing locking issue * Fixing makefile * Fixing race in config * Fixing race in status unit test * Adding EE race tests * Fixing race in cluster info * Removing code that's isn't needed * Fixing some more races * Fixing govet issue
Diffstat (limited to 'model/job.go')
-rw-r--r--model/job.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/model/job.go b/model/job.go
index 09d74aa09..a139b154c 100644
--- a/model/job.go
+++ b/model/job.go
@@ -5,6 +5,7 @@ package model
import (
"fmt"
+ "sync"
"time"
)
@@ -18,17 +19,24 @@ type ScheduledTask struct {
timer *time.Timer
}
+var taskMutex = sync.Mutex{}
var tasks = make(map[string]*ScheduledTask)
func addTask(task *ScheduledTask) {
+ taskMutex.Lock()
+ defer taskMutex.Unlock()
tasks[task.Name] = task
}
func removeTaskByName(name string) {
+ taskMutex.Lock()
+ defer taskMutex.Unlock()
delete(tasks, name)
}
func GetTaskByName(name string) *ScheduledTask {
+ taskMutex.Lock()
+ defer taskMutex.Unlock()
if task, ok := tasks[name]; ok {
return task
}
@@ -36,6 +44,8 @@ func GetTaskByName(name string) *ScheduledTask {
}
func GetAllTasks() *map[string]*ScheduledTask {
+ taskMutex.Lock()
+ defer taskMutex.Unlock()
return &tasks
}