(ws database.Workspace, templateSchedule schedule.TemplateScheduleOptions, lastBuild database.WorkspaceBuild, lastJob database.ProvisionerJob, currentTick time.Time)
| 655 | } |
| 656 | |
| 657 | func isEligibleForDelete(ws database.Workspace, templateSchedule schedule.TemplateScheduleOptions, lastBuild database.WorkspaceBuild, lastJob database.ProvisionerJob, currentTick time.Time) bool { |
| 658 | eligible := ws.DormantAt.Valid && ws.DeletingAt.Valid && |
| 659 | // Dormant workspaces should only be deleted if a time_til_dormant_autodelete value is specified. |
| 660 | templateSchedule.TimeTilDormantAutoDelete > 0 && |
| 661 | // The workspace must breach the time_til_dormant_autodelete value. |
| 662 | currentTick.After(ws.DeletingAt.Time) |
| 663 | |
| 664 | // If the last delete job failed we should wait 24 hours before trying again. |
| 665 | // Builds are resource-intensive so retrying every minute is not productive |
| 666 | // and will hold compute hostage. |
| 667 | if lastBuild.Transition == database.WorkspaceTransitionDelete && lastJob.JobStatus == database.ProvisionerJobStatusFailed { |
| 668 | return eligible && lastJob.Finished() && currentTick.Sub(lastJob.FinishedAt()) > time.Hour*24 |
| 669 | } |
| 670 | |
| 671 | return eligible |
| 672 | } |
| 673 | |
| 674 | // isEligibleForFailedCleanup returns true if the workspace is eligible to be |
| 675 | // stopped due to a failed build. A failed start is cleaned up by stopping it, |
no test coverage detected