Skip to content

feat: send native system notification on scheduled workspace shutdown #1414

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 6 commits into from
May 13, 2022
Merged
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
fixup! address PR comments
  • Loading branch information
johnstcn committed May 13, 2022
commit 55a1de235d82f193886c96fc32af6c786a6c874e
6 changes: 3 additions & 3 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func tryPollWorkspaceAutostop(ctx context.Context, client *codersdk.Client, work
lockStat, err := os.Stat(lockPath)
if err == nil {
// Lock file already exists for this workspace. How old is it?
lockAge := lockStat.ModTime().Sub(time.Now())
lockAge := time.Now().Sub(lockStat.ModTime())
if lockAge < 3*autostopPollInterval {
// Lock file exists and is still "fresh". Do nothing.
return func() {}
Expand All @@ -224,6 +224,8 @@ func tryPollWorkspaceAutostop(ctx context.Context, client *codersdk.Client, work
// Notify the user if the workspace is due to shutdown.
func notifyCondition(ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID, lockFile *os.File) notify.Condition {
return func(now time.Time) (deadline time.Time, callback func()) {
// update lockFile (best effort)
_ = os.Chtimes(lockFile.Name(), now, now)
ws, err := client.Workspace(ctx, workspaceID)
if err != nil {
return time.Time{}, nil
Expand Down Expand Up @@ -255,8 +257,6 @@ func notifyCondition(ctx context.Context, client *codersdk.Client, workspaceID u
}
// notify user with a native system notification (best effort)
_ = beeep.Notify(title, body, "")
// update lockFile (best effort)
_ = os.Chtimes(lockFile.Name(), now, now)
}
return deadline.Truncate(time.Minute), callback
}
Expand Down