@@ -360,6 +360,26 @@ func (*EnterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.C
360
360
return xerrors .Errorf ("update template schedule: %w" , err )
361
361
}
362
362
363
+ // Update all workspaces using the template to set the user defined schedule
364
+ // to be within the new bounds. This essentially does the following for each
365
+ // workspace using the template.
366
+ // if (template.ttl != NULL) {
367
+ // workspace.ttl = min(workspace.ttl, template.ttl)
368
+ // }
369
+ //
370
+ // NOTE: this does not apply to currently running workspaces as their
371
+ // schedule information is committed to the workspace_build during start.
372
+ // This limitation is displayed to the user while editing the template.
373
+ if opts .MaxTTL > 0 {
374
+ err = db .UpdateWorkspaceTTLToBeWithinTemplateMax (ctx , database.UpdateWorkspaceTTLToBeWithinTemplateMaxParams {
375
+ TemplateID : template .ID ,
376
+ TemplateMaxTTL : int64 (opts .MaxTTL ),
377
+ })
378
+ if err != nil {
379
+ return xerrors .Errorf ("update TTL of all workspaces on template to be within new template max TTL: %w" , err )
380
+ }
381
+ }
382
+
363
383
template , err = db .GetTemplateByID (ctx , tpl .ID )
364
384
if err != nil {
365
385
return xerrors .Errorf ("get updated template schedule: %w" , err )
@@ -371,25 +391,5 @@ func (*EnterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.C
371
391
return database.Template {}, err
372
392
}
373
393
374
- // Update all workspaces using the template to set the user defined schedule
375
- // to be within the new bounds. This essentially does the following for each
376
- // workspace using the template.
377
- // if (template.ttl != NULL) {
378
- // workspace.ttl = min(workspace.ttl, template.ttl)
379
- // }
380
- //
381
- // NOTE: this does not apply to currently running workspaces as their
382
- // schedule information is committed to the workspace_build during start.
383
- // This limitation is displayed to the user while editing the template.
384
- if opts .MaxTTL > 0 {
385
- err = db .UpdateWorkspaceTTLToBeWithinTemplateMax (ctx , database.UpdateWorkspaceTTLToBeWithinTemplateMaxParams {
386
- TemplateID : template .ID ,
387
- TemplateMaxTTL : int64 (opts .MaxTTL ),
388
- })
389
- if err != nil {
390
- return database.Template {}, xerrors .Errorf ("update TTL of all workspaces on template to be within new template max TTL: %w" , err )
391
- }
392
- }
393
-
394
394
return template , nil
395
395
}
0 commit comments