refactor: workspace autostop_schedule -> ttl#1578
Conversation
0593de8 to
22cd000
Compare
| if ws.TTL == nil || *ws.TTL == 0 { | ||
| return time.Time{}, nil | ||
| } |
There was a problem hiding this comment.
Instead of using a pointer why not just have 0 mean disabled?
There was a problem hiding this comment.
I considered that initially, but I think using the zero value could lead to bugs and/or unintended behaviour. Grey also preferred the semantics of nil | time.Duration from a FE consumption perspective.
There was a problem hiding this comment.
You do have a point, though -- 0 is already an invalid TTL.
There was a problem hiding this comment.
Comment: I think the FE or other clients having to know 0 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.
There was a problem hiding this comment.
Should we then consider that in the API response? We could return something like {"ttl": 0, "ttl_mode": "manual"}?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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 be nil or a number.
There was a problem hiding this comment.
Yeah, I feel like among go practitioners, 0 means disabled would be preferred to making it a pointer and nil means disabled.
greyscaled
left a comment
There was a problem hiding this comment.
Might need to generate the types, since I see codersdk 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?
| if ws.TTL == nil || *ws.TTL == 0 { | ||
| return time.Time{}, nil | ||
| } |
There was a problem hiding this comment.
Comment: I think the FE or other clients having to know 0 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.
mafredri
left a comment
There was a problem hiding this comment.
LGTM 👍🏻. Attached some (optional) suggestions.
| type UpdateWorkspaceAutostopRequest struct { | ||
| Schedule string `json:"schedule"` | ||
| type UpdateWorkspaceTTLRequest struct { | ||
| TTL *time.Duration `json:"ttl"` |
There was a problem hiding this comment.
Suggestion: Should we implement a custom Duration type like type NullDuration { Duration time.Duration; Valid bool } (optionally in a types or null package) with a custom json.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).
badcfec to
b3168c1
Compare
Co-authored-by: G r e y <grey@coder.com>
This PR makes the following changes:
autostop_schedulecolumn ofworkspaceswith attl.pq(still) does not supporttime.Duration.autostop_scheduletottlin database code etc.autostoptottl, updates API routes accordingly