isEligibleForAutostop returns true if the workspace should be autostopped.
(user database.User, ws database.Workspace, build database.WorkspaceBuild, job database.ProvisionerJob, currentTick time.Time)
| 623 | |
| 624 | // isEligibleForAutostop returns true if the workspace should be autostopped. |
| 625 | func isEligibleForAutostop(user database.User, ws database.Workspace, build database.WorkspaceBuild, job database.ProvisionerJob, currentTick time.Time) bool { |
| 626 | if job.JobStatus == database.ProvisionerJobStatusFailed { |
| 627 | return false |
| 628 | } |
| 629 | |
| 630 | // If the workspace is dormant we should not autostop it. |
| 631 | if ws.DormantAt.Valid { |
| 632 | return false |
| 633 | } |
| 634 | |
| 635 | if build.Transition == database.WorkspaceTransitionStart && user.Status == database.UserStatusSuspended { |
| 636 | return true |
| 637 | } |
| 638 | |
| 639 | // A workspace must be started in order for it to be auto-stopped. |
| 640 | return build.Transition == database.WorkspaceTransitionStart && |
| 641 | !build.Deadline.IsZero() && |
| 642 | // We do not want to stop a workspace prior to it breaching its deadline. |
| 643 | !currentTick.Before(build.Deadline) |
| 644 | } |
| 645 | |
| 646 | // isEligibleForDormantStop returns true if the workspace should be dormant |
| 647 | // for breaching the inactivity threshold of the template. |
no test coverage detected