MCPcopy
hub / github.com/dgraph-io/dgraph / InitTasks

Function InitTasks

worker/queue.go:88–114  ·  view source on GitHub ↗

InitTasks initializes the global Tasks variable.

()

Source from the content-addressed store, hash-verified

86
87// InitTasks initializes the global Tasks variable.
88func InitTasks() {
89 path := filepath.Join(x.WorkerConfig.TmpDir, "tasks.buf")
90 log, err := z.NewTreePersistent(path)
91 x.Check(err)
92
93 // #nosec G404: weak RNG
94 Tasks = &tasks{
95 queue: make(chan taskRequest, 16),
96 log: log,
97 logMu: new(sync.Mutex),
98 rng: rand.New(rand.NewSource(time.Now().UnixNano())),
99 }
100
101 // Mark all pending tasks as failed.
102 Tasks.logMu.Lock()
103 Tasks.log.IterateKV(func(id, val uint64) uint64 {
104 meta := TaskMeta(val)
105 if status := meta.Status(); status == TaskStatusQueued || status == TaskStatusRunning {
106 return uint64(newTaskMeta(meta.Kind(), TaskStatusFailed))
107 }
108 return 0
109 })
110 Tasks.logMu.Unlock()
111
112 // Start the task runner.
113 go Tasks.worker()
114}
115
116// tasks is a persistent task queue.
117type tasks struct {

Callers 1

runFunction · 0.92

Calls 8

CheckFunction · 0.92
TaskMetaTypeAlias · 0.85
newTaskMetaFunction · 0.85
StatusMethod · 0.80
KindMethod · 0.80
workerMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected