Skip to content

Commit cda7a9d

Browse files
authored
fix: reword autostop reminder to use relative countdown (#26948)
1 parent 40bceea commit cda7a9d

7 files changed

Lines changed: 18 additions & 14 deletions

File tree

coderd/autobuild/lifecycle_executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ func (e *Executor) runOnce(t time.Time) Stats {
565565
ws.OwnerID,
566566
notifications.TemplateWorkspaceAutostopReminder,
567567
map[string]string{
568-
"workspace": ws.Name,
569-
"deadline": reminderDeadline.UTC().Format(time.RFC1123),
568+
"workspace": ws.Name,
569+
"timeTilShutdown": humanize.Time(reminderDeadline),
570570
},
571571
"lifecycle_executor",
572572
// Associate this notification with all the related entities.

coderd/autobuild/lifecycle_executor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ func TestExecutorAutostopReminder(t *testing.T) {
19941994
require.Len(t, sent, 1)
19951995
require.Equal(t, workspace.OwnerID, sent[0].UserID)
19961996
require.Equal(t, workspace.Name, sent[0].Labels["workspace"])
1997-
require.Equal(t, deadline.UTC().Format(time.RFC1123), sent[0].Labels["deadline"])
1997+
require.NotEmpty(t, sent[0].Labels["timeTilShutdown"])
19981998
require.Contains(t, sent[0].Targets, workspace.ID)
19991999
require.Contains(t, sent[0].Targets, workspace.OwnerID)
20002000
require.Contains(t, sent[0].Targets, workspace.TemplateID)
@@ -2169,7 +2169,7 @@ func TestExecutorAutostopReminder(t *testing.T) {
21692169
testutil.TryReceive(ctx, t, statsCh)
21702170
sent := notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceAutostopReminder))
21712171
require.Len(t, sent, 1)
2172-
require.Equal(t, deadline.UTC().Format(time.RFC1123), sent[0].Labels["deadline"])
2172+
require.NotEmpty(t, sent[0].Labels["timeTilShutdown"])
21732173

21742174
// Move the deadline well into the future. The marker now differs from
21752175
// the build deadline, re-arming the reminder.
@@ -2188,7 +2188,7 @@ func TestExecutorAutostopReminder(t *testing.T) {
21882188
testutil.TryReceive(ctx, t, statsCh)
21892189
sent = notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceAutostopReminder))
21902190
require.Len(t, sent, 2)
2191-
require.Equal(t, newDeadline.UTC().Format(time.RFC1123), sent[1].Labels["deadline"])
2191+
require.NotEmpty(t, sent[1].Labels["timeTilShutdown"])
21922192
})
21932193

21942194
// ExceedsLifetime: a time_til_autostop_notify larger than the
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Revert to the body introduced by migration 000528.
2+
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';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Reword the autostop reminder to use a relative countdown instead of an
2+
-- absolute timestamp.
3+
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';

coderd/notifications/notifications_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,8 @@ func TestNotificationTemplates_Golden(t *testing.T) {
851851
UserEmail: "bobby@coder.com",
852852
UserUsername: "bobby",
853853
Labels: map[string]string{
854-
"workspace": "bobby-workspace",
855-
"deadline": "2024-03-15 14:00 UTC",
854+
"workspace": "bobby-workspace",
855+
"timeTilShutdown": "1 hour from now",
856856
},
857857
},
858858
},

coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Content-Type: text/plain; charset=UTF-8
1212

1313
Hi Bobby,
1414

15-
Your workspace bobby-workspace is scheduled to automatically stop at 2024-0=
16-
3-15 14:00 UTC.
15+
Your workspace bobby-workspace will automatically stop 1 hour from now.
1716

1817
Connect to it or extend the deadline to keep it running.
1918

@@ -49,8 +48,8 @@ argin: 8px 0 32px; line-height: 1.5;">
4948
</h1>
5049
<div style=3D"line-height: 1.5;">
5150
<p>Hi Bobby,</p>
52-
<p>Your workspace <strong>bobby-workspace</strong> is scheduled to =
53-
automatically stop at 2024-03-15 14:00 UTC.</p>
51+
<p>Your workspace <strong>bobby-workspace</strong> will automatical=
52+
ly stop 1 hour from now.</p>
5453

5554
<p>Connect to it or extend the deadline to keep it running.</p>
5655
</div>

coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
}
1717
],
1818
"labels": {
19-
"deadline": "2024-03-15 14:00 UTC",
19+
"timeTilShutdown": "1 hour from now",
2020
"workspace": "bobby-workspace"
2121
},
2222
"data": null,
2323
"targets": null
2424
},
2525
"title": "Your workspace \"bobby-workspace\" will stop soon",
2626
"title_markdown": "Your workspace \"bobby-workspace\" will stop soon",
27-
"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.",
28-
"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."
27+
"body": "Your workspace bobby-workspace will automatically stop 1 hour from now.\n\nConnect to it or extend the deadline to keep it running.",
28+
"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."
2929
}

0 commit comments

Comments
 (0)