@@ -149,6 +149,11 @@ func (e *Executor) runOnce(t time.Time) Stats {
149
149
return xerrors .Errorf ("get workspace by id: %w" , err )
150
150
}
151
151
152
+ user , err := tx .GetUserByID (e .ctx , ws .OwnerID )
153
+ if err != nil {
154
+ return xerrors .Errorf ("get user by id: %w" , err )
155
+ }
156
+
152
157
// Determine the workspace state based on its latest build.
153
158
latestBuild , err := tx .GetLatestWorkspaceBuildByWorkspaceID (e .ctx , ws .ID )
154
159
if err != nil {
@@ -172,7 +177,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
172
177
173
178
accessControl := (* (e .accessControlStore .Load ())).GetTemplateAccessControl (template )
174
179
175
- nextTransition , reason , err := getNextTransition (ws , latestBuild , latestJob , templateSchedule , currentTick )
180
+ nextTransition , reason , err := getNextTransition (user , ws , latestBuild , latestJob , templateSchedule , currentTick )
176
181
if err != nil {
177
182
log .Debug (e .ctx , "skipping workspace" , slog .Error (err ))
178
183
// err is used to indicate that a workspace is not eligible
@@ -300,6 +305,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
300
305
// may be "transitioning" to a new state (such as an inactive, stopped
301
306
// workspace transitioning to the dormant state).
302
307
func getNextTransition (
308
+ user database.User ,
303
309
ws database.Workspace ,
304
310
latestBuild database.WorkspaceBuild ,
305
311
latestJob database.ProvisionerJob ,
@@ -313,7 +319,7 @@ func getNextTransition(
313
319
switch {
314
320
case isEligibleForAutostop (ws , latestBuild , latestJob , currentTick ):
315
321
return database .WorkspaceTransitionStop , database .BuildReasonAutostop , nil
316
- case isEligibleForAutostart (ws , latestBuild , latestJob , templateSchedule , currentTick ):
322
+ case isEligibleForAutostart (user , ws , latestBuild , latestJob , templateSchedule , currentTick ):
317
323
return database .WorkspaceTransitionStart , database .BuildReasonAutostart , nil
318
324
case isEligibleForFailedStop (latestBuild , latestJob , templateSchedule , currentTick ):
319
325
return database .WorkspaceTransitionStop , database .BuildReasonAutostop , nil
@@ -334,7 +340,12 @@ func getNextTransition(
334
340
}
335
341
336
342
// isEligibleForAutostart returns true if the workspace should be autostarted.
337
- func isEligibleForAutostart (ws database.Workspace , build database.WorkspaceBuild , job database.ProvisionerJob , templateSchedule schedule.TemplateScheduleOptions , currentTick time.Time ) bool {
343
+ func isEligibleForAutostart (user database.User , ws database.Workspace , build database.WorkspaceBuild , job database.ProvisionerJob , templateSchedule schedule.TemplateScheduleOptions , currentTick time.Time ) bool {
344
+ // Don't attempt to autostart workspaces for suspended users.
345
+ if user .Status != database .UserStatusActive {
346
+ return false
347
+ }
348
+
338
349
// Don't attempt to autostart failed workspaces.
339
350
if job .JobStatus == database .ProvisionerJobStatusFailed {
340
351
return false
0 commit comments