(task *BuildTask)
| 127 | } |
| 128 | |
| 129 | func (q *BuildQueue) run(task *BuildTask) { |
| 130 | var output BuildOutput |
| 131 | |
| 132 | defer func() { |
| 133 | if r := recover(); r != nil { |
| 134 | output.err = fmt.Errorf("build panic: %v", r) |
| 135 | task.ctx.status = "error" |
| 136 | task.ctx.logger.Errorf("build '%s' panicked: %v", task.ctx.Path(), r) |
| 137 | } |
| 138 | |
| 139 | waitChans := task.waitChans |
| 140 | |
| 141 | q.lock.Lock() |
| 142 | q.chann++ |
| 143 | delete(q.queue, task) |
| 144 | delete(q.tasks, task.ctx.Path()) |
| 145 | if task.ctx.rawPath != "" { |
| 146 | // the `Build` function may have changed the path |
| 147 | delete(q.tasks, task.ctx.rawPath) |
| 148 | } |
| 149 | q.startSchedulerLocked() |
| 150 | q.lock.Unlock() |
| 151 | |
| 152 | for _, ch := range waitChans { |
| 153 | if ch == nil { |
| 154 | continue |
| 155 | } |
| 156 | select { |
| 157 | case ch <- output: |
| 158 | default: |
| 159 | // the request may have already timed out while waiting on the build |
| 160 | } |
| 161 | } |
| 162 | }() |
| 163 | |
| 164 | buildTimeout := 10 * time.Minute |
| 165 | if config != nil && config.BuildTimeout > 0 { |
| 166 | buildTimeout = time.Duration(config.BuildTimeout) * time.Second |
| 167 | } |
| 168 | buildCtx, cancel := context.WithTimeout(context.Background(), buildTimeout) |
| 169 | defer cancel() |
| 170 | |
| 171 | meta, err := task.ctx.Build(buildCtx) |
| 172 | if errors.Is(err, context.DeadlineExceeded) { |
| 173 | err = fmt.Errorf("build timeout after %d seconds", buildTimeout/time.Second) |
| 174 | } |
| 175 | if err == nil { |
| 176 | task.ctx.status = "done" |
| 177 | if task.ctx.target == "types" { |
| 178 | task.ctx.logger.Infof("build '%s'(types) done in %v", task.ctx.Path(), time.Since(task.startedAt)) |
| 179 | } else { |
| 180 | task.ctx.logger.Infof("build '%s' done in %v", task.ctx.Path(), time.Since(task.startedAt)) |
| 181 | } |
| 182 | } else { |
| 183 | task.ctx.status = "error" |
| 184 | task.ctx.logger.Errorf("build '%s': %v", task.ctx.Path(), err) |
| 185 | } |
| 186 | output = BuildOutput{meta: meta, err: err} |
no test coverage detected