Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add locked TTL field to template meta#8020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sreya merged 8 commits intomainfromjon/lockedttl
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

11 changes: 9 additions & 2 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 2 additions & 1 deletioncoderd/database/dump.sql
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE templates DROP COLUMN locked_ttl;
COMMIT;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE templates ADD COLUMN locked_ttl BIGINT NOT NULL DEFAULT 0;
COMMIT;
9 changes: 5 additions & 4 deletionscoderd/database/modelqueries.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
pq.Array(arg.IDs),
)
iferr!=nil {
returnnil,err
returnnil,xerrors.Errorf("query context: %w",err)
}
deferrows.Close()
varitems []Template
Expand DownExpand Up@@ -82,16 +82,17 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
&i.AllowUserAutostop,
&i.FailureTTL,
&i.InactivityTTL,
&i.LockedTTL,
);err!=nil {
returnnil,err
returnnil,xerrors.Errorf("scan: %w",err)
}
items=append(items,i)
}
iferr:=rows.Close();err!=nil {
returnnil,err
returnnil,xerrors.Errorf("close: %w",err)
}
iferr:=rows.Err();err!=nil {
returnnil,err
returnnil,xerrors.Errorf("rowserr: %w",err)
}
returnitems,nil
}
Expand Down
1 change: 1 addition & 0 deletionscoderd/database/models.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

29 changes: 20 additions & 9 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 2 additions & 1 deletioncoderd/database/queries/templates.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -120,7 +120,8 @@ SET
default_ttl = $5,
max_ttl = $6,
failure_ttl = $7,
inactivity_ttl = $8
inactivity_ttl = $8,
locked_ttl = $9
WHERE
id = $1
RETURNING
Expand Down
1 change: 1 addition & 0 deletionscoderd/database/sqlc.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ overrides:
failure_ttl: FailureTTL
inactivity_ttl: InactivityTTL
eof: EOF
locked_ttl: LockedTTL

sql:
- schema: "./dump.sql"
Expand Down
10 changes: 7 additions & 3 deletionscoderd/schedule/template.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,12 @@ type TemplateScheduleOptions struct {
//
// If set, users cannot disable automatic workspace shutdown.
MaxTTL time.Duration `json:"max_ttl"`
//IfFailureTTLis set, allfailed workspaces will be stopped automatically after this time has elapsed.
// FailureTTLdictates the duration after whichfailed workspaces will be stopped automatically.
FailureTTL time.Duration `json:"failure_ttl"`
//IfInactivityTTLis set, allinactive workspaces will bedeleted automatically after this time has elapsed.
// InactivityTTLdictates the duration after whichinactive workspaces will belocked.
InactivityTTL time.Duration `json:"inactivity_ttl"`
// LockedTTL dictates the duration after which locked workspaces will be permanently deleted.
LockedTTL time.Duration `json:"locked_ttl"`
}

// TemplateScheduleStore provides an interface for retrieving template
Expand DownExpand Up@@ -51,11 +53,12 @@ func (*agplTemplateScheduleStore) GetTemplateScheduleOptions(ctx context.Context
UserAutostartEnabled: true,
UserAutostopEnabled: true,
DefaultTTL: time.Duration(tpl.DefaultTTL),
// Disregard the values in the database, since MaxTTL, FailureTTL, andInactivityTTL are enterprise
// Disregard the values in the database, since MaxTTL, FailureTTL,InactivityTTL,andLockedTTL are enterprise
// features.
MaxTTL: 0,
FailureTTL: 0,
InactivityTTL: 0,
LockedTTL: 0,
}, nil
}

Expand All@@ -76,5 +79,6 @@ func (*agplTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.Context
MaxTTL: tpl.MaxTTL,
FailureTTL: tpl.FailureTTL,
InactivityTTL: tpl.InactivityTTL,
LockedTTL: tpl.LockedTTL,
})
}
13 changes: 12 additions & 1 deletioncoderd/templates.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -497,6 +497,12 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
if req.InactivityTTLMillis < 0 {
validErrs = append(validErrs, codersdk.ValidationError{Field: "inactivity_ttl_ms", Detail: "Must be a positive integer."})
}
if req.InactivityTTLMillis < 0 {
validErrs = append(validErrs, codersdk.ValidationError{Field: "inactivity_ttl_ms", Detail: "Must be a positive integer."})
}
if req.LockedTTLMillis < 0 {
validErrs = append(validErrs, codersdk.ValidationError{Field: "locked_ttl_ms", Detail: "Must be a positive integer."})
}

if len(validErrs) > 0 {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Expand All@@ -518,7 +524,8 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
req.DefaultTTLMillis == time.Duration(template.DefaultTTL).Milliseconds() &&
req.MaxTTLMillis == time.Duration(template.MaxTTL).Milliseconds() &&
req.FailureTTLMillis == time.Duration(template.FailureTTL).Milliseconds() &&
req.InactivityTTLMillis == time.Duration(template.InactivityTTL).Milliseconds() {
req.InactivityTTLMillis == time.Duration(template.InactivityTTL).Milliseconds() &&
req.FailureTTLMillis == time.Duration(template.LockedTTL).Milliseconds() {
return nil
}

Expand DownExpand Up@@ -546,11 +553,13 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
maxTTL := time.Duration(req.MaxTTLMillis) * time.Millisecond
failureTTL := time.Duration(req.FailureTTLMillis) * time.Millisecond
inactivityTTL := time.Duration(req.InactivityTTLMillis) * time.Millisecond
lockedTTL := time.Duration(req.LockedTTLMillis) * time.Millisecond

if defaultTTL != time.Duration(template.DefaultTTL) ||
maxTTL != time.Duration(template.MaxTTL) ||
failureTTL != time.Duration(template.FailureTTL) ||
inactivityTTL != time.Duration(template.InactivityTTL) ||
lockedTTL != time.Duration(template.LockedTTL) ||
req.AllowUserAutostart != template.AllowUserAutostart ||
req.AllowUserAutostop != template.AllowUserAutostop {
updated, err = (*api.TemplateScheduleStore.Load()).SetTemplateScheduleOptions(ctx, tx, updated, schedule.TemplateScheduleOptions{
Expand All@@ -563,6 +572,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
MaxTTL: maxTTL,
FailureTTL: failureTTL,
InactivityTTL: inactivityTTL,
LockedTTL: lockedTTL,
})
if err != nil {
return xerrors.Errorf("set template schedule options: %w", err)
Expand DownExpand Up@@ -716,5 +726,6 @@ func (api *API) convertTemplate(
AllowUserCancelWorkspaceJobs: template.AllowUserCancelWorkspaceJobs,
FailureTTLMillis: time.Duration(template.FailureTTL).Milliseconds(),
InactivityTTLMillis: time.Duration(template.InactivityTTL).Milliseconds(),
LockedTTLMillis: time.Duration(template.LockedTTL).Milliseconds(),
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp