QueueTask to queue single Task
(ctx context.Context, t Task)
| 182 | |
| 183 | // QueueTask to queue single Task |
| 184 | func (q *queue) QueueTask(ctx context.Context, t Task) error { |
| 185 | if atomic.LoadInt32(&q.stopFlag) == 1 { |
| 186 | return ErrQueueShutdown |
| 187 | } |
| 188 | |
| 189 | if t.Status() != task.StatusSuspending { |
| 190 | q.metric.IncSubmittedTask() |
| 191 | if err := q.transitStatus(ctx, t, task.StatusQueued); err != nil { |
| 192 | return err |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if err := q.scheduler.Queue(t); err != nil { |
| 197 | return err |
| 198 | } |
| 199 | owner := "" |
| 200 | if t.Owner() != nil { |
| 201 | owner = t.Owner().Email |
| 202 | } |
| 203 | q.logger.Info("New Task with type %q submitted to queue %q by %q", t.Type(), q.name, owner) |
| 204 | if q.registry != nil { |
| 205 | q.registry.Set(t.ID(), t) |
| 206 | } |
| 207 | |
| 208 | return nil |
| 209 | } |
| 210 | |
| 211 | // newContext creates a new context for a new Task iteration. |
| 212 | func (q *queue) newContext(t Task) context.Context { |
no test coverage detected