doCleanFinish wraps a call to do() with cleaning up the job and setting the terminal messages
(ctx context.Context)
| 377 | |
| 378 | // doCleanFinish wraps a call to do() with cleaning up the job and setting the terminal messages |
| 379 | func (r *Runner) doCleanFinish(ctx context.Context) { |
| 380 | var ( |
| 381 | failedJob *proto.FailedJob |
| 382 | completedJob *proto.CompletedJob |
| 383 | ) |
| 384 | |
| 385 | // push the fail/succeed write onto the defer stack before the cleanup, so |
| 386 | // that cleanup happens before this. |
| 387 | defer func() { |
| 388 | _, span := r.startTrace(ctx, tracing.FuncName()) |
| 389 | defer span.End() |
| 390 | |
| 391 | if failedJob != nil { |
| 392 | r.setFail(failedJob) |
| 393 | return |
| 394 | } |
| 395 | r.setComplete(completedJob) |
| 396 | }() |
| 397 | |
| 398 | var err error |
| 399 | r.session, err = r.provisioner.Session(ctx) |
| 400 | if err != nil { |
| 401 | failedJob = r.failedJobf("open session: %s", err) |
| 402 | return |
| 403 | } |
| 404 | defer r.session.Close() |
| 405 | |
| 406 | defer func() { |
| 407 | ctx, span := r.startTrace(ctx, tracing.FuncName()) |
| 408 | defer span.End() |
| 409 | |
| 410 | r.queueLog(ctx, &proto.Log{ |
| 411 | Source: proto.LogSource_PROVISIONER_DAEMON, |
| 412 | Level: sdkproto.LogLevel_INFO, |
| 413 | Stage: "Cleaning Up", |
| 414 | CreatedAt: time.Now().UnixMilli(), |
| 415 | }) |
| 416 | r.flushQueuedLogs(ctx) |
| 417 | }() |
| 418 | |
| 419 | completedJob, failedJob = r.do(ctx) |
| 420 | } |
| 421 | |
| 422 | // do actually does the work of running the job |
| 423 | func (r *Runner) do(ctx context.Context) (*proto.CompletedJob, *proto.FailedJob) { |
no test coverage detected