@@ -11,12 +11,13 @@ import { Link as RouterLink } from "react-router-dom"
11
11
import { Workspace } from "../../api/typesGenerated"
12
12
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
13
13
import { extractTimezone , stripTimezone } from "../../util/schedule"
14
+ import { isWorkspaceOn } from "../../util/workspace"
14
15
import { Stack } from "../Stack/Stack"
15
16
16
17
dayjs . extend ( duration )
17
18
dayjs . extend ( relativeTime )
18
19
19
- const Language = {
20
+ export const Language = {
20
21
autoStartDisplay : ( schedule : string ) : string => {
21
22
if ( schedule ) {
22
23
return cronstrue . toString ( stripTimezone ( schedule ) , { throwExceptionOnParseError : false } )
@@ -33,24 +34,31 @@ const Language = {
33
34
}
34
35
} ,
35
36
autoStopDisplay : ( workspace : Workspace ) : string => {
36
- const latest = workspace . latest_build
37
+ const deadline = workspace . latest_build . deadline
38
+ const ttl = workspace . ttl
37
39
38
- if ( ! workspace . ttl || workspace . ttl < 1 ) {
39
- return "Manual"
40
- }
41
-
42
- if ( latest . transition === "start" ) {
40
+ if ( isWorkspaceOn ( workspace ) ) {
41
+ // Workspace is on --> derive from latest_build.deadline. Note that the
42
+ // user may modify their workspace object (ttl) while the workspace is
43
+ // running and depending on system semantics, the deadline may still
44
+ // represent the previously defined ttl. Thus, we always derive from the
45
+ // deadline as the source of truth.
43
46
const now = dayjs ( )
44
- const updatedAt = dayjs ( latest . updated_at )
45
- const deadline = updatedAt . add ( workspace . ttl / 1_000_000 , "ms" )
46
47
if ( now . isAfter ( deadline ) ) {
47
48
return "Workspace is shutting down now"
49
+ } else {
50
+ return now . to ( deadline )
48
51
}
49
- return now . to ( deadline )
52
+ } else if ( ! ttl || ttl < 1 ) {
53
+ // If the workspace is not on, and the ttl is 0 or undefined, then the
54
+ // workspace is set to manually shutdown.
55
+ return "Manual"
56
+ } else {
57
+ // The workspace has a ttl set, but is either in an unknown state or is
58
+ // not running. Therefore, we derive from workspace.ttl.
59
+ const duration = dayjs . duration ( ttl / 1_000_000 , "milliseconds" )
60
+ return `${ duration . humanize ( ) } after start`
50
61
}
51
-
52
- const duration = dayjs . duration ( workspace . ttl / 1_000_000 , "milliseconds" )
53
- return `${ duration . humanize ( ) } after start`
54
62
} ,
55
63
editScheduleLink : "Edit schedule" ,
56
64
schedule : "Schedule" ,
0 commit comments