@@ -19,8 +19,10 @@ import (
19
19
"github.com/coder/coder/v2/coderd/database/dbtime"
20
20
"github.com/coder/coder/v2/coderd/database/provisionerjobs"
21
21
"github.com/coder/coder/v2/coderd/database/pubsub"
22
+ "github.com/coder/coder/v2/coderd/notifications"
22
23
"github.com/coder/coder/v2/coderd/schedule"
23
24
"github.com/coder/coder/v2/coderd/wsbuilder"
25
+ "github.com/coder/coder/v2/enterprise/coderd/dormancy"
24
26
)
25
27
26
28
// Executor automatically starts or stops workspaces.
@@ -34,6 +36,8 @@ type Executor struct {
34
36
log slog.Logger
35
37
tick <- chan time.Time
36
38
statsCh chan <- Stats
39
+ // NotificationsEnqueuer handles enqueueing notifications for delivery by SMTP, webhook, etc.
40
+ notificationsEnqueuer notifications.Enqueuer
37
41
}
38
42
39
43
// Stats contains information about one run of Executor.
@@ -44,7 +48,7 @@ type Stats struct {
44
48
}
45
49
46
50
// New returns a new wsactions executor.
47
- func NewExecutor (ctx context.Context , db database.Store , ps pubsub.Pubsub , tss * atomic.Pointer [schedule.TemplateScheduleStore ], auditor * atomic.Pointer [audit.Auditor ], acs * atomic.Pointer [dbauthz.AccessControlStore ], log slog.Logger , tick <- chan time.Time ) * Executor {
51
+ func NewExecutor (ctx context.Context , db database.Store , ps pubsub.Pubsub , tss * atomic.Pointer [schedule.TemplateScheduleStore ], auditor * atomic.Pointer [audit.Auditor ], acs * atomic.Pointer [dbauthz.AccessControlStore ], log slog.Logger , tick <- chan time.Time , ntf notifications. Enqueuer ) * Executor {
48
52
le := & Executor {
49
53
//nolint:gocritic // Autostart has a limited set of permissions.
50
54
ctx : dbauthz .AsAutostart (ctx ),
@@ -55,6 +59,7 @@ func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, tss *
55
59
log : log .Named ("autobuild" ),
56
60
auditor : auditor ,
57
61
accessControlStore : acs ,
62
+ notificationsEnqueuer : ntf ,
58
63
}
59
64
return le
60
65
}
@@ -215,6 +220,18 @@ func (e *Executor) runOnce(t time.Time) Stats {
215
220
},
216
221
})
217
222
223
+ dormancy .NotifyWorkspaceDormant (
224
+ e .ctx ,
225
+ e .log ,
226
+ e .notificationsEnqueuer ,
227
+ dormancy.WorkspaceDormantNotification {
228
+ Workspace : ws ,
229
+ Initiator : "system" ,
230
+ Reason : "breached the template's threshold for inactivity" ,
231
+ CreatedBy : "lifecycleexecutor" ,
232
+ },
233
+ )
234
+
218
235
auditLog = & auditParams {
219
236
Old : wsOld ,
220
237
New : ws ,
0 commit comments