Skip to content

feat: Add codersdk.NullTime, change workspace build deadline #3552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Site references to workspace.latest_build.deadline
  • Loading branch information
mafredri committed Aug 25, 2022
commit e390cefa413e02772f30b898525c492c7cb85430
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ NoTTL.args = {
...Mocks.MockWorkspace,
latest_build: {
...Mocks.MockWorkspaceBuild,
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// SEE: #1834
deadline: "0001-01-01T00:00:00Z",
deadline: undefined,
},
ttl_ms: undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe("WorkspaceScheduleBanner", () => {
describe("shouldDisplay", () => {
// Manual TTL case
it("should not display if the build does not have a deadline", () => {
// Given: a workspace with deadline of '"0001-01-01T00:00:00Z"'
// Given: a workspace with deadline of undefined.
const workspace: TypesGen.Workspace = {
...Mocks.MockWorkspace,
latest_build: {
...Mocks.MockWorkspaceBuild,
deadline: "0001-01-01T00:00:00Z",
deadline: undefined,
transition: "start",
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export const shouldDisplay = (workspace: TypesGen.Workspace): boolean => {
if (!isWorkspaceOn(workspace)) {
return false
} else {
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// SEE: #1834
if (!workspace.latest_build.deadline) {
return false
}
const deadline = dayjs(workspace.latest_build.deadline).utc()
const hasDeadline = deadline.year() > 1
const thirtyMinutesFromNow = dayjs().add(30, "minutes").utc()
return hasDeadline && deadline.isSameOrBefore(thirtyMinutesFromNow)
return deadline.isSameOrBefore(thirtyMinutesFromNow)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ NoTTL.args = {
...Mocks.MockWorkspace,
latest_build: {
...Mocks.MockWorkspaceBuild,
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// SEE: #1834
deadline: "0001-01-01T00:00:00Z",
deadline: undefined,
},
ttl_ms: undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ dayjs.extend(relativeTime)
dayjs.extend(timezone)

export const shouldDisplayPlusMinus = (workspace: Workspace): boolean => {
if (!isWorkspaceOn(workspace)) {
return false
}
const deadline = dayjs(workspace.latest_build.deadline).utc()
return deadline.year() > 1
return isWorkspaceOn(workspace) && !!workspace.latest_build.deadline
}

export interface WorkspaceScheduleButtonProps {
Expand Down
13 changes: 6 additions & 7 deletions site/src/util/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,26 @@ export const autoStartDisplay = (schedule: string | undefined): string => {

export const isShuttingDown = (workspace: Workspace, deadline?: Dayjs): boolean => {
if (!deadline) {
if (!workspace.latest_build.deadline) {
return false
}
deadline = dayjs(workspace.latest_build.deadline).utc()
}
const hasDeadline = deadline.year() > 1
const now = dayjs().utc()
return isWorkspaceOn(workspace) && hasDeadline && now.isAfter(deadline)
return isWorkspaceOn(workspace) && now.isAfter(deadline)
}

export const autoStopDisplay = (workspace: Workspace): string => {
const deadline = dayjs(workspace.latest_build.deadline).utc()
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// SEE: #1834
const hasDeadline = deadline.year() > 1
const ttl = workspace.ttl_ms

if (isWorkspaceOn(workspace) && hasDeadline) {
if (isWorkspaceOn(workspace) && workspace.latest_build.deadline) {
// Workspace is on --> derive from latest_build.deadline. Note that the
// user may modify their workspace object (ttl) while the workspace is
// running and depending on system semantics, the deadline may still
// represent the previously defined ttl. Thus, we always derive from the
// deadline as the source of truth.

const deadline = dayjs(workspace.latest_build.deadline).utc()
if (isShuttingDown(workspace, deadline)) {
return Language.workspaceShuttingDownLabel
} else {
Expand Down