Skip to content

Commit 6431a0e

Browse files
committed
Merge branch 'main' into 17-account-notifs
2 parents 67a5137 + 58b810f commit 6431a0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+668
-420
lines changed

.github/workflows/ci.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,15 @@ jobs:
788788
echo "tag=$tag" >> $GITHUB_OUTPUT
789789
790790
# build images for each architecture
791-
make -j build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
791+
# note: omitting the -j argument to avoid race conditions when pushing
792+
make build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
792793
793794
# only push if we are on main branch
794795
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
795796
# build and push multi-arch manifest, this depends on the other images
796797
# being pushed so will automatically push them
797-
make -j push/build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
798+
# note: omitting the -j argument to avoid race conditions when pushing
799+
make push/build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
798800
799801
# Define specific tags
800802
tags=("$tag" "main" "latest")

coderd/autobuild/lifecycle_executor.go

+22-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/coder/coder/v2/coderd/database/dbtime"
2020
"github.com/coder/coder/v2/coderd/database/provisionerjobs"
2121
"github.com/coder/coder/v2/coderd/database/pubsub"
22-
"github.com/coder/coder/v2/coderd/dormancy"
2322
"github.com/coder/coder/v2/coderd/notifications"
2423
"github.com/coder/coder/v2/coderd/schedule"
2524
"github.com/coder/coder/v2/coderd/wsbuilder"
@@ -145,10 +144,11 @@ func (e *Executor) runOnce(t time.Time) Stats {
145144
var (
146145
job *database.ProvisionerJob
147146
auditLog *auditParams
148-
dormantNotification *dormancy.WorkspaceDormantNotification
147+
shouldNotifyDormancy bool
149148
nextBuild *database.WorkspaceBuild
150149
activeTemplateVersion database.TemplateVersion
151150
ws database.Workspace
151+
tmpl database.Template
152152
didAutoUpdate bool
153153
)
154154
err := e.db.InTx(func(tx database.Store) error {
@@ -182,17 +182,17 @@ func (e *Executor) runOnce(t time.Time) Stats {
182182
return xerrors.Errorf("get template scheduling options: %w", err)
183183
}
184184

185-
template, err := tx.GetTemplateByID(e.ctx, ws.TemplateID)
185+
tmpl, err = tx.GetTemplateByID(e.ctx, ws.TemplateID)
186186
if err != nil {
187187
return xerrors.Errorf("get template by ID: %w", err)
188188
}
189189

190-
activeTemplateVersion, err = tx.GetTemplateVersionByID(e.ctx, template.ActiveVersionID)
190+
activeTemplateVersion, err = tx.GetTemplateVersionByID(e.ctx, tmpl.ActiveVersionID)
191191
if err != nil {
192192
return xerrors.Errorf("get active template version by ID: %w", err)
193193
}
194194

195-
accessControl := (*(e.accessControlStore.Load())).GetTemplateAccessControl(template)
195+
accessControl := (*(e.accessControlStore.Load())).GetTemplateAccessControl(tmpl)
196196

197197
nextTransition, reason, err := getNextTransition(user, ws, latestBuild, latestJob, templateSchedule, currentTick)
198198
if err != nil {
@@ -215,7 +215,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
215215
log.Debug(e.ctx, "autostarting with active version")
216216
builder = builder.ActiveVersion()
217217

218-
if latestBuild.TemplateVersionID != template.ActiveVersionID {
218+
if latestBuild.TemplateVersionID != tmpl.ActiveVersionID {
219219
// control flag to know if the workspace was auto-updated,
220220
// so the lifecycle executor can notify the user
221221
didAutoUpdate = true
@@ -248,12 +248,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
248248
return xerrors.Errorf("update workspace dormant deleting at: %w", err)
249249
}
250250

251-
dormantNotification = &dormancy.WorkspaceDormantNotification{
252-
Workspace: ws,
253-
Initiator: "autobuild",
254-
Reason: "breached the template's threshold for inactivity",
255-
CreatedBy: "lifecycleexecutor",
256-
}
251+
shouldNotifyDormancy = true
257252

258253
log.Info(e.ctx, "dormant workspace",
259254
slog.F("last_used_at", ws.LastUsedAt),
@@ -325,14 +320,24 @@ func (e *Executor) runOnce(t time.Time) Stats {
325320
return xerrors.Errorf("post provisioner job to pubsub: %w", err)
326321
}
327322
}
328-
if dormantNotification != nil {
329-
_, err = dormancy.NotifyWorkspaceDormant(
323+
if shouldNotifyDormancy {
324+
_, err = e.notificationsEnqueuer.Enqueue(
330325
e.ctx,
331-
e.notificationsEnqueuer,
332-
*dormantNotification,
326+
ws.OwnerID,
327+
notifications.TemplateWorkspaceDormant,
328+
map[string]string{
329+
"name": ws.Name,
330+
"reason": "inactivity exceeded the dormancy threshold",
331+
"timeTilDormant": time.Duration(tmpl.TimeTilDormant).String(),
332+
},
333+
"lifecycle_executor",
334+
ws.ID,
335+
ws.OwnerID,
336+
ws.TemplateID,
337+
ws.OrganizationID,
333338
)
334339
if err != nil {
335-
log.Warn(e.ctx, "failed to notify of workspace marked as dormant", slog.Error(err), slog.F("workspace_id", dormantNotification.Workspace.ID))
340+
log.Warn(e.ctx, "failed to notify of workspace marked as dormant", slog.Error(err), slog.F("workspace_id", ws.ID))
336341
}
337342
}
338343
return nil

coderd/autobuild/lifecycle_executor_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ func TestNotifications(t *testing.T) {
11221122
require.Contains(t, notifyEnq.Sent[0].Targets, workspace.ID)
11231123
require.Contains(t, notifyEnq.Sent[0].Targets, workspace.OrganizationID)
11241124
require.Contains(t, notifyEnq.Sent[0].Targets, workspace.OwnerID)
1125-
require.Equal(t, notifyEnq.Sent[0].Labels["initiator"], "autobuild")
11261125
})
11271126
}
11281127

0 commit comments

Comments
 (0)