Skip to content

Conversation

stirby
Copy link
Contributor

@stirby stirby commented Jan 18, 2024

Hotfix for
coder/coder#11652

https://github.com/coder/customers/issues/400

Halves maximum time to display workspace autostop warning notification.

@stirby stirby requested a review from code-asher January 18, 2024 19:00
return Math.abs(new Date().getTime() - new Date(workspace.latest_build.deadline).getTime()) <= hourMilli
const halfHourMilli = 1000 * 60 * 30
// return workspaces with a deadline that is in 30 min or less
return Math.abs(new Date().getTime() - new Date(workspace.latest_build.deadline).getTime()) <= halfHourMilli
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the notif text would still say an hour so you'll have to adjust I think

Copy link
Contributor Author

@stirby stirby Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that the notification text took the time to impendingActionDeadline from the workspace's true deadline not this check?

  updateNotificationLists() {
    this.#workspacesApproachingAutostop = this.#ownedWorkspaces
      .filter(this.filterWorkspacesImpendingAutostop)
      .map((workspace) =>
        this.transformWorkspaceObjects(workspace, this.#workspacesApproachingAutostop, workspace.latest_build.deadline),
      )
      

  transformWorkspaceObjects(workspace: Workspace, workspaceList: NotifiedWorkspace[], deadlineField: string) {
    const wasNotified = workspaceList.find((nw) => nw.workspace.id === workspace.id)?.wasNotified ?? false
    const impendingActionDeadline = formatDistanceToNowStrict(new Date(deadlineField))
    return { workspace, wasNotified, impendingActionDeadline }
  }
  
  notifyImpendingAutostop() {
    this.#workspacesApproachingAutostop?.forEach((notifiedWorkspace: NotifiedWorkspace) => {
      if (notifiedWorkspace.wasNotified) {
        // don't message the user; we've already messaged
        return
      }

      // we display individual notifications for each workspace as VS Code
      // intentionally strips new lines from the message text
      // https://github.com/Microsoft/vscode/issues/48900
      this.vscodeProposed.window.showInformationMessage(
        `${notifiedWorkspace.workspace.name} is scheduled to shut down in ${notifiedWorkspace.impendingActionDeadline}.`,
      )
      notifiedWorkspace.wasNotified = true
    })
  }

@code-asher code-asher merged commit bccc486 into main Jan 18, 2024
@code-asher code-asher deleted the notif-hotfix branch January 18, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants