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{})
| 129 | // - *pb.BackupRequest |
| 130 | // - *pb.ExportRequest |
| 131 | func (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 |