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

refactor: workspace autostop_schedule -> ttl#1578

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
greyscaled merged 15 commits intomainfromcj/workspace-autostop-ttl
May 19, 2022

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedMay 18, 2022
edited
Loading

This PR makes the following changes:

  • Adds a migration to replace theautostop_schedule column ofworkspaces with attl.
  • Replaces all existing usages ofautostop_schedule tottl in database code etc.
  • Renames CLI commandautostop tottl, updates API routes accordingly
    • Note: To maintain consistency with the autostart behaviour, ttl is truncated to time.Minute. A zero value or only seconds value for TTL is not valid per the CLI.
  • Lifecycle executor now checks if TTL is set and greater than 0 instead of checking the next scheduled time of autostop schedule.
    • Note: I am doing a small bit of fudging of the autostop deadline by adding one minute to ensure that we don't terminate too early.

greyscaled reacted with laugh emoji
@johnstcnjohnstcn self-assigned thisMay 18, 2022
@johnstcnjohnstcnforce-pushed thecj/workspace-autostop-ttl branch 2 times, most recently from0593de8 to22cd000CompareMay 19, 2022 11:21
@johnstcnjohnstcn marked this pull request as ready for reviewMay 19, 2022 13:41
@johnstcnjohnstcn requested a review froma teamMay 19, 2022 13:55
Comment on lines +273 to 274
ifws.TTL==nil||*ws.TTL==0 {
return time.Time{},nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using a pointer why not just have0 mean disabled?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I considered that initially, but I think using the zero value could lead to bugs and/or unintended behaviour. Grey also preferred the semantics ofnil | time.Duration from a FE consumption perspective.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

You do have a point, though -- 0 is already an invalid TTL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: I think the FE or other clients having to know0 means "manual" is unfortunate, but I'm willing to accept it if it's cleaner for our backend/APIs.

As stated earlier, from v2 forwards I believe it's best that we look at the Coder system as a frontend for a backend, not the other way around.

Copy link
Member

Choose a reason for hiding this comment

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

Should we then consider that in the API response? We could return something like{"ttl": 0, "ttl_mode": "manual"}?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's certainly golang convention to make use of "zero-values" in this way, but I don't think we should extend that to the HTTP API, CLI, or frontend, which should behave in ways that are independent of golang's idioms.

greyscaled and johnstcn reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

@spikecurtis are you referring to@deansheather 's comment here:#1578 (comment)

why not just have 0 mean disabled?

Or the fact that we're using a pointer such that the value can benil or a number.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I feel like among go practitioners, 0 means disabled would be preferred to making it a pointer andnil means disabled.

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.

Might need to generate the types, since I seecodersdk changed types.

This will have FE breakages.

If you don't mind, I can push those fixes to this PR so that it's all taken care of in one. Are you cool with that?

Comment on lines +273 to 274
ifws.TTL==nil||*ws.TTL==0 {
return time.Time{},nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: I think the FE or other clients having to know0 means "manual" is unfortunate, but I'm willing to accept it if it's cleaner for our backend/APIs.

As stated earlier, from v2 forwards I believe it's best that we look at the Coder system as a frontend for a backend, not the other way around.

@johnstcnjohnstcn requested a review froma team as acode ownerMay 19, 2022 16:35
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.

LGTM 👍🏻. Attached some (optional) suggestions.

typeUpdateWorkspaceAutostopRequeststruct {
Schedulestring`json:"schedule"`
typeUpdateWorkspaceTTLRequeststruct {
TTL*time.Duration`json:"ttl"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Should we implement a custom Duration type liketype NullDuration { Duration time.Duration; Valid bool } (optionally in atypes ornull package) with a customjson.Marshaler? I'm mostly thinking about (Go) consumers here. It's not possible to e.g. do:

req:=UpdateWorkspaceTTLRequest {TTL:&time.Duration(time.Second),}

without first assigning to a variable. Similarly the pointer usage could lead to null pointer dereferences (which arguably would be the "correct" behavior, unless it's known that the zero value is OK).

@johnstcnjohnstcnforce-pushed thecj/workspace-autostop-ttl branch frombadcfec tob3168c1CompareMay 19, 2022 18:34
@greyscaledgreyscaled changed the titlerefactor: workspace: autostop_schedule -> ttlrefactor: workspace autostop_schedule -> ttlMay 19, 2022
@greyscaledgreyscaled merged commitd72c45e intomainMay 19, 2022
@greyscaledgreyscaled deleted the cj/workspace-autostop-ttl branchMay 19, 2022 19:09
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
Co-authored-by: G r e y <grey@coder.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mafredrimafredrimafredri approved these changes

@spikecurtisspikecurtisspikecurtis left review comments

@deansheatherdeansheatherdeansheather left review comments

+2 more reviewers

@dwahlerdwahlerdwahler left review comments

@greyscaledgreyscaledgreyscaled approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@johnstcnjohnstcn

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@johnstcn@mafredri@dwahler@spikecurtis@greyscaled@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp