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 default autostart and ttl for new workspaces#1632

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
johnstcn merged 12 commits intomainfromcj/default-autostart-ttl
May 23, 2022

Conversation

johnstcn
Copy link
Member

What

This PR adds default values for autostart and TTL values for all new workspaces.

NOTE: I am open to just keeping the TTL and leaving the autostart if folks think that's preferable.

Fixes#634

greyscaled reacted with thumbs up emoji
@johnstcnjohnstcn requested a review froma teamMay 20, 2022 17:47
@johnstcnjohnstcn requested a review froma team as acode ownerMay 20, 2022 17:47
@johnstcnjohnstcn self-assigned thisMay 20, 2022
@@ -94,6 +94,9 @@ export interface CreateWorkspaceBuildRequest {
export interface CreateWorkspaceRequest {
readonly template_id: string
readonly name: string
readonly autostart_schedule?: string
// This is likely an enum in an external package ("time.Duration")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@Emyrk Can we not have this happen for time.Duration?

Comment on lines +58 to +60
if schedule.Location == time.Local {
return nil, xerrors.Errorf("schedules scoped to time.Local are not supported")
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

NOTE: added an extra check here, we don't want these sneaking in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

TIL:time.Local !=time.UTC even whenTZ=UTC, cool!

Copy link
Contributor

@greyscaledgreyscaled left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

FE = ✔️

@johnstcnjohnstcnenabled auto-merge (squash)May 21, 2022 00:26
@ammario
Copy link
Member

Is this implemented globally or by template? Also, how does one create a workspace without a TTL?

@johnstcnjohnstcndisabled auto-mergeMay 21, 2022 15:43
@ammario
Copy link
Member

ammario commentedMay 23, 2022
edited
Loading

If it happens we're implementing it site-level, we should consider implementing it on the organization level. See#617.

@johnstcn
Copy link
MemberAuthor

Is this implemented globally or by template?

Only by workspace right now. There's a separate issue for by-template.

Also, how does one create a workspace without a TTL?

I figured we would want to enforce a default TTL that users can then un-set if required. If this isn't the case, we can add an opt-out option.

@ammario
Copy link
Member

Is this implemented globally or by template?

Only by workspace right now. There's a separate issue for by-template.

Oh, I meant the default. It looks like it's implemented installation-wide with a CLI flag.

Also, how does one create a workspace without a TTL?

I figured we would want to enforce a default TTL that users can then un-set if required. If this isn't the case, we can add an opt-out option.

I think this is fine.

And, I can see how implementing it site-wide via CLI first is easier than doing an org option.

johnstcn reacted with thumbs up emoji

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Code changes look good! Some small suggestions, feel free to amend or dismiss.

@@ -54,6 +60,20 @@ func create() *cobra.Command {
}
}

tz, err := time.LoadLocation(tzName)
if err != nil {
return xerrors.Errorf("Invalid workspace autostart timezone: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit: Error strings should not be capitalized:https://github.com/golang/go/wiki/CodeReviewComments#error-strings

f0ssel and johnstcn reacted with thumbs up emoji
cli/create.go Outdated
@@ -207,5 +229,10 @@ func create() *cobra.Command {
cliui.AllowSkipPrompt(cmd)
cliflag.StringVarP(cmd.Flags(), &templateName, "template", "t", "CODER_TEMPLATE_NAME", "", "Specify a template name.")
cliflag.StringVarP(cmd.Flags(), &parameterFile, "parameter-file", "", "CODER_PARAMETER_FILE", "", "Specify a file path with parameter values.")
cliflag.StringVarP(cmd.Flags(), &autostartMinute, "autostart-minute", "", "CODER_WORKSPACE_AUTOSTART", "0", "Specify the minute(s) at which the workspace should autostart.")
cliflag.StringVarP(cmd.Flags(), &autostartHour, "autostart-hour", "", "CODER_WORKSPACE_AUTOSTART", "9", "Specify the hour(s) at which the workspace should autostart.")
cliflag.StringVarP(cmd.Flags(), &autostartDow, "autostart-day-of-week", "", "CODER_WORKSPACE_AUTOSTART", "MON-FRI", "Specify the days(s) on which the workspace should autostart.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A user might wonder how this should look if they want Monday, Wednesday and Friday (e.g.MON,WED,FRI, multiple flags)? Should we add some examples to illustrate acceptable formats to the user?

johnstcn reacted with thumbs up emoji
cli/create.go Outdated
cliflag.StringVarP(cmd.Flags(), &autostartHour, "autostart-hour", "", "CODER_WORKSPACE_AUTOSTART", "9", "Specify the hour(s) at which the workspace should autostart.")
cliflag.StringVarP(cmd.Flags(), &autostartDow, "autostart-day-of-week", "", "CODER_WORKSPACE_AUTOSTART", "MON-FRI", "Specify the days(s) on which the workspace should autostart.")
cliflag.StringVarP(cmd.Flags(), &tzName, "tz", "", "TZ", "", "Specify your timezone location for workspace autostart.")
cliflag.DurationVarP(cmd.Flags(), &ttl, "ttl", "", "CODER_WORKSPACE_TTL", 8*time.Hour, "Specify a TTL for the workspace.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
cliflag.DurationVarP(cmd.Flags(),&ttl,"ttl","","CODER_WORKSPACE_TTL",8*time.Hour,"Specify a TTL for the workspace.")
cliflag.DurationVarP(cmd.Flags(),&ttl,"ttl","","CODER_WORKSPACE_TTL",8*time.Hour,"Specify atime-to-live (TTL) for the workspace.")

johnstcn and greyscaled reacted with thumbs up emoji
err := cmd.Execute()
require.EqualError(t, err, "Invalid workspace autostart timezone: unknown time zone invalid")
}()
<-doneChan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As we were hunting this style today, should we eliminate them here as well? 😄

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For these ones, I'm going to just useassert instead ofrequire.

mafredri reacted with thumbs up emoji
Comment on lines +58 to +60
if schedule.Location == time.Local {
return nil, xerrors.Errorf("schedules scoped to time.Local are not supported")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

TIL:time.Local !=time.UTC even whenTZ=UTC, cool!

Name: createWorkspace.Name,
ID: uuid.New(),
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Minor: Do we want to use the same value for these?

johnstcn reacted with thumbs up emoji
Name string `json:"name" validate:"username,required"`
TemplateID uuid.UUID `json:"template_id" validate:"required"`
Name string `json:"name" validate:"username,required"`
AutostartSchedule *string `json:"autostart_schedule" validate:""`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
AutostartSchedule*string`json:"autostart_schedule" validate:""`
AutostartSchedule*string`json:"autostart_schedule"`

johnstcn reacted with thumbs up emoji
@@ -41,6 +41,13 @@ func Test_Weekly(t *testing.T) {
expectedTz: "UTC",
expectedString: "CRON_TZ=UTC 30 9 * * 1-5",
},
{
name: "time.Local will bite you",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

❤️

@@ -357,6 +357,25 @@ func (api *api) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
return
}

var dbAutostartSchedule sql.NullString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't have a strong reasoning for this, but I don't love using nullstring. I know there's a lot ofNOT NULL DEFAULT '' in v1 and I generally prefer than to handling a null type. Do you have any thoughts on this?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is it mainly the extra overhead of managing the pointer type as opposed to just checking for the empty string?
I can do a separate PR to migrate these types on the database layer, but I'd like to keep the existingnull | String API for the FE.

greyscaled reacted with thumbs up emoji
Copy link
Contributor

@greyscaledgreyscaled left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

:shipit:

@johnstcnjohnstcn merged commitb202076 intomainMay 23, 2022
@johnstcnjohnstcn deleted the cj/default-autostart-ttl branchMay 23, 2022 22:31
@johnstcn
Copy link
MemberAuthor

:shipit:

TIL what the squirrel detective signifies. 🤣

kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
* database: add autostart_schedule and ttl to InsertWorkspace; make gen* coderd: workspaces: consume additional fields of CreateWorkspaceRequest* cli: update: add support for TTL and autostart_schedule* cli: create: add unit tests* coder: import  `time/tzdata` for embedded timezone database* autobuild: fix unit test that only runs with a real db
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@greyscaledgreyscaledgreyscaled left review comments

@f0sself0sself0ssel left review comments

@mafredrimafredrimafredri approved these changes

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add Default Auto Off for all new workspaces
5 participants
@johnstcn@ammario@mafredri@greyscaled@f0ssel

[8]ページ先頭

©2009-2025 Movatter.jp