isEligibleForFailedCleanup returns true if the workspace is eligible to be stopped due to a failed build. A failed start is cleaned up by stopping it, and a failed stop is retried by issuing another stop. In both cases the remediation is a stop build.
(build database.WorkspaceBuild, job database.ProvisionerJob, templateSchedule schedule.TemplateScheduleOptions, currentTick time.Time)
| 676 | // and a failed stop is retried by issuing another stop. In both cases the |
| 677 | // remediation is a stop build. |
| 678 | func isEligibleForFailedCleanup(build database.WorkspaceBuild, job database.ProvisionerJob, templateSchedule schedule.TemplateScheduleOptions, currentTick time.Time) bool { |
| 679 | // If the template has specified a failure TTL. |
| 680 | return templateSchedule.FailureTTL > 0 && |
| 681 | // And the job resulted in failure. |
| 682 | job.JobStatus == database.ProvisionerJobStatusFailed && |
| 683 | (build.Transition == database.WorkspaceTransitionStart || |
| 684 | build.Transition == database.WorkspaceTransitionStop) && |
| 685 | // And sufficient time has elapsed since the job has completed. |
| 686 | job.CompletedAt.Valid && |
| 687 | currentTick.Sub(job.CompletedAt.Time) > templateSchedule.FailureTTL |
| 688 | } |
| 689 | |
| 690 | type auditParams struct { |
| 691 | Old database.WorkspaceTable |