Fail immediately halts updates and, if the job is not complete sends FailJob to the coder server. Running goroutines are canceled but complete asynchronously (although they are prevented from further updating the job to the coder server). The provided context sets how long to keep trying to send the
(ctx context.Context, f *proto.FailedJob)
| 267 | // are canceled but complete asynchronously (although they are prevented from further updating the job to the coder |
| 268 | // server). The provided context sets how long to keep trying to send the FailJob. |
| 269 | func (r *Runner) Fail(ctx context.Context, f *proto.FailedJob) error { |
| 270 | f.JobId = r.job.JobId |
| 271 | r.mutex.Lock() |
| 272 | defer r.mutex.Unlock() |
| 273 | if !r.okToSend { |
| 274 | return nil // already done |
| 275 | } |
| 276 | r.Cancel() |
| 277 | if r.failedJob == nil { |
| 278 | r.failedJob = f |
| 279 | r.cond.Signal() |
| 280 | } |
| 281 | // here we keep the original failed reason if there already was one, but we hadn't yet sent it. It is likely more |
| 282 | // informative of the job failing due to some problem running it, whereas this function is used to externally |
| 283 | // force a Fail. |
| 284 | err := r.sender.FailJob(ctx, r.failedJob) |
| 285 | r.okToSend = false |
| 286 | r.stop() |
| 287 | close(r.done) |
| 288 | return err |
| 289 | } |
| 290 | |
| 291 | // setComplete is an internal function to set the job to completed. This does not send the completedJob. |
| 292 | func (r *Runner) setComplete(c *proto.CompletedJob) { |