fix: reword autostop reminder to use relative countdown (#26948)

This commit is contained in:
Jon Ayers
2026-07-01 21:24:42 -05:00
committed by GitHub
parent 40bceeaf8d
commit cda7a9d4f4
7 changed files with 18 additions and 14 deletions
+2 -2
View File
@@ -565,8 +565,8 @@ func (e *Executor) runOnce(t time.Time) Stats {
ws.OwnerID,
notifications.TemplateWorkspaceAutostopReminder,
map[string]string{
"workspace": ws.Name,
"deadline": reminderDeadline.UTC().Format(time.RFC1123),
"workspace": ws.Name,
"timeTilShutdown": humanize.Time(reminderDeadline),
},
"lifecycle_executor",
// Associate this notification with all the related entities.
+3 -3
View File
@@ -1994,7 +1994,7 @@ func TestExecutorAutostopReminder(t *testing.T) {
require.Len(t, sent, 1)
require.Equal(t, workspace.OwnerID, sent[0].UserID)
require.Equal(t, workspace.Name, sent[0].Labels["workspace"])
require.Equal(t, deadline.UTC().Format(time.RFC1123), sent[0].Labels["deadline"])
require.NotEmpty(t, sent[0].Labels["timeTilShutdown"])
require.Contains(t, sent[0].Targets, workspace.ID)
require.Contains(t, sent[0].Targets, workspace.OwnerID)
require.Contains(t, sent[0].Targets, workspace.TemplateID)
@@ -2169,7 +2169,7 @@ func TestExecutorAutostopReminder(t *testing.T) {
testutil.TryReceive(ctx, t, statsCh)
sent := notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceAutostopReminder))
require.Len(t, sent, 1)
require.Equal(t, deadline.UTC().Format(time.RFC1123), sent[0].Labels["deadline"])
require.NotEmpty(t, sent[0].Labels["timeTilShutdown"])
// Move the deadline well into the future. The marker now differs from
// the build deadline, re-arming the reminder.
@@ -2188,7 +2188,7 @@ func TestExecutorAutostopReminder(t *testing.T) {
testutil.TryReceive(ctx, t, statsCh)
sent = notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceAutostopReminder))
require.Len(t, sent, 2)
require.Equal(t, newDeadline.UTC().Format(time.RFC1123), sent[1].Labels["deadline"])
require.NotEmpty(t, sent[1].Labels["timeTilShutdown"])
})
// ExceedsLifetime: a time_til_autostop_notify larger than the
@@ -0,0 +1,2 @@
-- Revert to the body introduced by migration 000528.
UPDATE notification_templates SET body_template = E'Your workspace **{{.Labels.workspace}}** is scheduled to automatically stop at {{.Labels.deadline}}.\n\nConnect to it or extend the deadline to keep it running.' WHERE id = '6f6cb984-c167-4fa5-bb87-1058dd642779';
@@ -0,0 +1,3 @@
-- Reword the autostop reminder to use a relative countdown instead of an
-- absolute timestamp.
UPDATE notification_templates SET body_template = E'Your workspace **{{.Labels.workspace}}** will automatically stop {{.Labels.timeTilShutdown}}.\n\nConnect to it or extend the deadline to keep it running.' WHERE id = '6f6cb984-c167-4fa5-bb87-1058dd642779';
+2 -2
View File
@@ -851,8 +851,8 @@ func TestNotificationTemplates_Golden(t *testing.T) {
UserEmail: "bobby@coder.com",
UserUsername: "bobby",
Labels: map[string]string{
"workspace": "bobby-workspace",
"deadline": "2024-03-15 14:00 UTC",
"workspace": "bobby-workspace",
"timeTilShutdown": "1 hour from now",
},
},
},
@@ -12,8 +12,7 @@ Content-Type: text/plain; charset=UTF-8
Hi Bobby,
Your workspace bobby-workspace is scheduled to automatically stop at 2024-0=
3-15 14:00 UTC.
Your workspace bobby-workspace will automatically stop 1 hour from now.
Connect to it or extend the deadline to keep it running.
@@ -49,8 +48,8 @@ argin: 8px 0 32px; line-height: 1.5;">
</h1>
<div style=3D"line-height: 1.5;">
<p>Hi Bobby,</p>
<p>Your workspace <strong>bobby-workspace</strong> is scheduled to =
automatically stop at 2024-03-15 14:00 UTC.</p>
<p>Your workspace <strong>bobby-workspace</strong> will automatical=
ly stop 1 hour from now.</p>
<p>Connect to it or extend the deadline to keep it running.</p>
</div>
@@ -16,7 +16,7 @@
}
],
"labels": {
"deadline": "2024-03-15 14:00 UTC",
"timeTilShutdown": "1 hour from now",
"workspace": "bobby-workspace"
},
"data": null,
@@ -24,6 +24,6 @@
},
"title": "Your workspace \"bobby-workspace\" will stop soon",
"title_markdown": "Your workspace \"bobby-workspace\" will stop soon",
"body": "Your workspace bobby-workspace is scheduled to automatically stop at 2024-03-15 14:00 UTC.\n\nConnect to it or extend the deadline to keep it running.",
"body_markdown": "Your workspace **bobby-workspace** is scheduled to automatically stop at 2024-03-15 14:00 UTC.\n\nConnect to it or extend the deadline to keep it running."
"body": "Your workspace bobby-workspace will automatically stop 1 hour from now.\n\nConnect to it or extend the deadline to keep it running.",
"body_markdown": "Your workspace **bobby-workspace** will automatically stop 1 hour from now.\n\nConnect to it or extend the deadline to keep it running."
}