@@ -580,7 +580,11 @@ WHERE
580
580
) AND
581
581
582
582
(
583
- -- isEligibleForAutostop
583
+ -- A workspace may be eligible for autostop if the following are true:
584
+ -- * The provisioner job has not failed.
585
+ -- * The workspace is not dormant.
586
+ -- * The workspace build was a start transition.
587
+ -- * The workspace's owner is suspended OR the workspace build deadline has passed.
584
588
(
585
589
provisioner_jobs .job_status != ' failed' ::provisioner_job_status AND
586
590
workspaces .dormant_at IS NULL AND
@@ -592,22 +596,33 @@ WHERE
592
596
)
593
597
) OR
594
598
595
- -- isEligibleForAutostart
599
+ -- A workspace may be eligible for autostart if the following are true:
600
+ -- * The workspace's owner is active.
601
+ -- * The provisioner job did not failed.
602
+ -- * The workspace build was a stop transition.
603
+ -- * The workspace has an autostart schedule.
596
604
(
597
605
users .status = ' active' ::user_status AND
598
606
provisioner_jobs .job_status != ' failed' ::provisioner_job_status AND
599
607
workspace_builds .transition = ' stop' ::workspace_transition AND
600
608
workspaces .autostart_schedule IS NOT NULL
601
609
) OR
602
610
603
- -- isEligibleForDormantStop
611
+ -- A workspace may be eligible for dormant stop if the following are true:
612
+ -- * The workspace is not dormant.
613
+ -- * The template has set a time til dormant.
614
+ -- * The workspace has been unused for longer than the time til dormancy.
604
615
(
605
616
workspaces .dormant_at IS NULL AND
606
617
templates .time_til_dormant > 0 AND
607
618
(@now :: timestamptz ) - workspaces .last_used_at > (INTERVAL ' 1 millisecond' * (templates .time_til_dormant / 1000000 ))
608
619
) OR
609
620
610
- -- isEligibleForDelete
621
+ -- A workspace may be eligible for deletion if the following are true:
622
+ -- * The workspace is dormant.
623
+ -- * The workspace is scheduled to be deleted.
624
+ -- * If there was a prior attempt to delete the workspace that failed:
625
+ -- * This attempt was at least 24 hours ago>
611
626
(
612
627
workspaces .dormant_at IS NOT NULL AND
613
628
workspaces .deleting_at IS NOT NULL AND
@@ -632,11 +647,16 @@ WHERE
632
647
END
633
648
) OR
634
649
635
- -- isEligibleForFailedStop
650
+ -- A workspace may be eligible for failed stop if the following are true:
651
+ -- * The template has a failure ttl set.
652
+ -- * The workspace build was a start transition.
653
+ -- * The provisioner job failed.
654
+ -- * The provisioner job had completed.
655
+ -- * The provisioner job has been completed for longer than the failure ttl.
636
656
(
637
657
templates .failure_ttl > 0 AND
638
- provisioner_jobs .job_status = ' failed' ::provisioner_job_status AND
639
658
workspace_builds .transition = ' start' ::workspace_transition AND
659
+ provisioner_jobs .job_status = ' failed' ::provisioner_job_status AND
640
660
provisioner_jobs .completed_at IS NOT NULL AND
641
661
(@now :: timestamptz ) - provisioner_jobs .completed_at > (INTERVAL ' 1 millisecond' * (templates .failure_ttl / 1000000 ))
642
662
)
0 commit comments