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

Method Enqueue

worker/queue.go:131–159  ·  view source on GitHub ↗

Enqueue adds a new task to the queue, waits for 3 seconds, and returns any errors that may have happened in that span of time. The request must be of type: - *pb.BackupRequest - *pb.ExportRequest

(req interface{})

Source from the content-addressed store, hash-verified

129// - *pb.BackupRequest
130// - *pb.ExportRequest
131func (t *tasks) Enqueue(req interface{}) (uint64, error) {
132 if t == nil {
133 return 0, fmt.Errorf("task queue hasn't been initialized yet")
134 }
135
136 id, err := t.enqueue(req)
137 if err != nil {
138 return 0, err
139 }
140
141 // Wait for upto 3 seconds to check for errors.
142 for range 3 {
143 time.Sleep(time.Second)
144
145 t.logMu.Lock()
146 meta := TaskMeta(t.log.Get(id))
147 t.logMu.Unlock()
148
149 // Early return
150 switch meta.Status() {
151 case TaskStatusFailed:
152 return 0, fmt.Errorf("task failed")
153 case TaskStatusSuccess:
154 return id, nil
155 }
156 }
157
158 return id, nil
159}
160
161// enqueue adds a new task to the queue. This must be of type:
162// - *pb.BackupRequest

Callers 2

resolveBackupFunction · 0.80
resolveExportFunction · 0.80

Calls 7

enqueueMethod · 0.95
TaskMetaTypeAlias · 0.85
StatusMethod · 0.80
GetMethod · 0.65
ErrorfMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected