| 72 | } |
| 73 | |
| 74 | func (q *BuildQueue) Snapshot() []map[string]any { |
| 75 | q.lock.Lock() |
| 76 | defer q.lock.Unlock() |
| 77 | |
| 78 | items := make([]map[string]any, 0, len(q.queue)+q.pending.Len()) |
| 79 | for task := range q.queue { |
| 80 | items = append(items, map[string]any{ |
| 81 | "waitClients": len(task.waitChans), |
| 82 | "createdAt": task.createdAt.Format(time.RFC1123), |
| 83 | "path": task.ctx.Path(), |
| 84 | "status": task.ctx.status, |
| 85 | }) |
| 86 | } |
| 87 | for el := q.pending.Front(); el != nil; el = el.Next() { |
| 88 | task, ok := el.Value.(*BuildTask) |
| 89 | if !ok { |
| 90 | continue |
| 91 | } |
| 92 | items = append(items, map[string]any{ |
| 93 | "waitClients": len(task.waitChans), |
| 94 | "createdAt": task.createdAt.Format(time.RFC1123), |
| 95 | "path": task.ctx.Path(), |
| 96 | "status": task.ctx.status, |
| 97 | }) |
| 98 | } |
| 99 | return items |
| 100 | } |
| 101 | |
| 102 | func (q *BuildQueue) startSchedulerLocked() { |
| 103 | if q.scheduler || q.chann == 0 || q.pending.Len() == 0 { |