Skip to content

Commit 5ffa6da

Browse files
feat: add inactivity cleanup and failure cleanup configuration fields to Template Schedule Form (#7402)
* added workspace actions entitlement * added workspace actions experiment * added new route for template enterprise meta * removing new route; repurposing old * add new fields to get endpoints * removed workspace actions experiment * added logic to enterprise template store * added new form fields * feature flagged new fields * fix validation * fixed submit btn * fix tests * changed ttl defaults * added FE tests * added BE tests * fixed lint * adjusted comment language * fixing unstaged changes check * fix test * Update coderd/database/migrations/000122_add_template_cleanup_ttls.down.sql Co-authored-by: Dean Sheather <dean@deansheather.com> * Update coderd/database/migrations/000122_add_template_cleanup_ttls.up.sql Co-authored-by: Dean Sheather <dean@deansheather.com> --------- Co-authored-by: Dean Sheather <dean@deansheather.com>
1 parent 3632ac8 commit 5ffa6da

33 files changed

+578
-59
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"Dsts",
3535
"embeddedpostgres",
3636
"enablements",
37+
"enterprisemeta",
3738
"errgroup",
3839
"eventsourcemock",
3940
"Failf",

coderd/apidoc/docs.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbfake/databasefake.go

+2
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,8 @@ func (q *fakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database
19451945
tpl.UpdatedAt = database.Now()
19461946
tpl.DefaultTTL = arg.DefaultTTL
19471947
tpl.MaxTTL = arg.MaxTTL
1948+
tpl.FailureTTL = arg.FailureTTL
1949+
tpl.InactivityTTL = arg.InactivityTTL
19481950
q.templates[idx] = tpl
19491951
return tpl.DeepCopy(), nil
19501952
}

coderd/database/dump.sql

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BEGIN;
2+
ALTER TABLE ONLY templates DROP COLUMN IF EXISTS failure_ttl;
3+
ALTER TABLE ONLY templates DROP COLUMN IF EXISTS inactivity_ttl;
4+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BEGIN;
2+
ALTER TABLE ONLY templates ADD COLUMN IF NOT EXISTS failure_ttl BIGINT NOT NULL DEFAULT 0;
3+
ALTER TABLE ONLY templates ADD COLUMN IF NOT EXISTS inactivity_ttl BIGINT NOT NULL DEFAULT 0;
4+
COMMIT;

coderd/database/modelqueries.go

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
8080
&i.MaxTTL,
8181
&i.AllowUserAutostart,
8282
&i.AllowUserAutostop,
83+
&i.FailureTTL,
84+
&i.InactivityTTL,
8385
); err != nil {
8486
return nil, err
8587
}

coderd/database/models.go

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+31-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

+3-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ SET
118118
allow_user_autostart = $3,
119119
allow_user_autostop = $4,
120120
default_ttl = $5,
121-
max_ttl = $6
121+
max_ttl = $6,
122+
failure_ttl = $7,
123+
inactivity_ttl = $8
122124
WHERE
123125
id = $1
124126
RETURNING

coderd/database/sqlc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ overrides:
5151
template_max_ttl: TemplateMaxTTL
5252
motd_file: MOTDFile
5353
uuid: UUID
54+
failure_ttl: FailureTTL
55+
inactivity_ttl: InactivityTTL
5456

5557
sql:
5658
- schema: "./dump.sql"

coderd/schedule/template.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type TemplateScheduleOptions struct {
1818
//
1919
// If set, users cannot disable automatic workspace shutdown.
2020
MaxTTL time.Duration `json:"max_ttl"`
21+
// If FailureTTL is set, all failed workspaces will be stopped automatically after this time has elapsed.
22+
FailureTTL time.Duration `json:"failure_ttl"`
23+
// If InactivityTTL is set, all inactive workspaces will be deleted automatically after this time has elapsed.
24+
InactivityTTL time.Duration `json:"inactivity_ttl"`
2125
}
2226

2327
// TemplateScheduleStore provides an interface for retrieving template
@@ -47,9 +51,11 @@ func (*agplTemplateScheduleStore) GetTemplateScheduleOptions(ctx context.Context
4751
UserAutostartEnabled: true,
4852
UserAutostopEnabled: true,
4953
DefaultTTL: time.Duration(tpl.DefaultTTL),
50-
// Disregard the value in the database, since MaxTTL is an enterprise
51-
// feature.
52-
MaxTTL: 0,
54+
// Disregard the values in the database, since MaxTTL, FailureTTL, and InactivityTTL are enterprise
55+
// features.
56+
MaxTTL: 0,
57+
FailureTTL: 0,
58+
InactivityTTL: 0,
5359
}, nil
5460
}
5561

@@ -68,5 +74,7 @@ func (*agplTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.Context
6874
AllowUserAutostart: tpl.AllowUserAutostart,
6975
AllowUserAutostop: tpl.AllowUserAutostop,
7076
MaxTTL: tpl.MaxTTL,
77+
FailureTTL: tpl.FailureTTL,
78+
InactivityTTL: tpl.InactivityTTL,
7179
})
7280
}

0 commit comments

Comments
 (0)