mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add codersdk.NullTime, change workspace build deadline (#3552)
Fixes #2015 Co-authored-by: Joe Previte <jjprevite@gmail.com>
This commit is contained in:
co-authored by
Joe Previte
parent
a21a6d2f4a
commit
78a24941fe
@@ -527,7 +527,7 @@ export interface WorkspaceBuild {
|
||||
readonly initiator_id: string
|
||||
readonly initiator_name: string
|
||||
readonly job: ProvisionerJob
|
||||
readonly deadline: string
|
||||
readonly deadline?: string
|
||||
readonly reason: BuildReason
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -23,16 +23,12 @@ export interface WorkspaceScheduleBannerProps {
|
||||
}
|
||||
|
||||
export const shouldDisplay = (workspace: TypesGen.Workspace): boolean => {
|
||||
if (!isWorkspaceOn(workspace)) {
|
||||
if (!isWorkspaceOn(workspace) || !workspace.latest_build.deadline) {
|
||||
return false
|
||||
} else {
|
||||
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
|
||||
// SEE: #1834
|
||||
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)
|
||||
}
|
||||
const deadline = dayjs(workspace.latest_build.deadline).utc()
|
||||
const thirtyMinutesFromNow = dayjs().add(30, "minutes").utc()
|
||||
return deadline.isSameOrBefore(thirtyMinutesFromNow)
|
||||
}
|
||||
|
||||
export const WorkspaceScheduleBanner: FC<React.PropsWithChildren<WorkspaceScheduleBannerProps>> = ({
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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) && Boolean(workspace.latest_build.deadline)
|
||||
}
|
||||
|
||||
export interface WorkspaceScheduleButtonProps {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user