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
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/workspaceAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class WorkspaceAction {
return false
}

const hourMilli = 1000 * 60 * 60
// return workspaces with a deadline that is in 1 hr or less
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
    })
  }

}

filterWorkspacesImpendingDeletion(workspace: Workspace): workspace is WorkspaceWithDeletingAt {
Expand Down