mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: update workspace TTL on template TTL change (#15761)
Relates to https://github.com/coder/coder/issues/15390 Currently when a user creates a workspace, their workspace's TTL is determined by the template's default TTL. If the Coder instance is AGPL, or if the template has disallowed the user from configuring autostop, then it is not possible to change the workspace's TTL after creation. Any changes to the template's default TTL only takes effect on _new_ workspaces. This PR modifies the behaviour slightly so that on AGPL Coder, or on enterprise when a template does not allow user's to configure their workspace's TTL, updating the template's default TTL will also update any workspace's TTL to match this value.
This commit is contained in:
@@ -195,6 +195,23 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
|
||||
return xerrors.Errorf("get updated template schedule: %w", err)
|
||||
}
|
||||
|
||||
// Update all workspace's TTL using this template if either of the following:
|
||||
// - The template's AllowUserAutostop has just been disabled
|
||||
// - The template's TTL has been modified and AllowUserAutostop is disabled
|
||||
if !opts.UserAutostopEnabled && (tpl.AllowUserAutostop || int64(opts.DefaultTTL) != tpl.DefaultTTL) {
|
||||
var ttl sql.NullInt64
|
||||
if opts.DefaultTTL != 0 {
|
||||
ttl = sql.NullInt64{Valid: true, Int64: int64(opts.DefaultTTL)}
|
||||
}
|
||||
|
||||
if err = tx.UpdateWorkspacesTTLByTemplateID(ctx, database.UpdateWorkspacesTTLByTemplateIDParams{
|
||||
TemplateID: template.ID,
|
||||
Ttl: ttl,
|
||||
}); err != nil {
|
||||
return xerrors.Errorf("update workspaces ttl by template id %q: %w", template.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Recalculate max_deadline and deadline for all running workspace
|
||||
// builds on this template.
|
||||
err = s.updateWorkspaceBuilds(ctx, tx, template)
|
||||
|
||||
Reference in New Issue
Block a user