Skip to content
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

halved notification check for autostop warning #189

Merged
merged 1 commit into from
Jan 18, 2024
Merged

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.

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
2 checks passed
@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