Add adds a new build task to the queue.
(ctx *BuildContext)
| 45 | |
| 46 | // Add adds a new build task to the queue. |
| 47 | func (q *BuildQueue) Add(ctx *BuildContext) chan BuildOutput { |
| 48 | q.lock.Lock() |
| 49 | defer q.lock.Unlock() |
| 50 | |
| 51 | ch := make(chan BuildOutput, 1) |
| 52 | |
| 53 | task, ok := q.tasks[ctx.Path()] |
| 54 | if ok { |
| 55 | task.waitChans = append(task.waitChans, ch) |
| 56 | return ch |
| 57 | } |
| 58 | |
| 59 | task = &BuildTask{ |
| 60 | ctx: ctx, |
| 61 | createdAt: time.Now(), |
| 62 | waitChans: []chan BuildOutput{ch}, |
| 63 | } |
| 64 | ctx.status = "pending" |
| 65 | |
| 66 | q.pending.PushBack(task) |
| 67 | q.tasks[ctx.Path()] = task |
| 68 | |
| 69 | q.startSchedulerLocked() |
| 70 | |
| 71 | return ch |
| 72 | } |
| 73 | |
| 74 | func (q *BuildQueue) Snapshot() []map[string]any { |
| 75 | q.lock.Lock() |
no test coverage detected