-
Notifications
You must be signed in to change notification settings - Fork 887
feat: allow bumping workspace deadline #1828
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
39a53c2
f764e61
2a74312
6f2bef5
dcd57cf
c31b9dd
23247d4
41306aa
d9a795f
3ecb323
4b868d2
cfeb274
b5be82c
9a45186
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,7 +597,7 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) { | |
return xerrors.Errorf("workspace must be started, current status: %s", build.Transition) | ||
} | ||
|
||
newDeadline := req.Deadline.Truncate(time.Minute).UTC() | ||
newDeadline := req.Deadline.UTC() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice getting rid of the truncates! 💪🏻 |
||
if newDeadline.IsZero() { | ||
// This should not be possible because the struct validation field enforces a non-zero value. | ||
code = http.StatusBadRequest | ||
|
@@ -609,8 +609,8 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) { | |
return xerrors.Errorf("new deadline %q must be after existing deadline %q", newDeadline.Format(time.RFC3339), build.Deadline.Format(time.RFC3339)) | ||
} | ||
|
||
// both newDeadline and build.Deadline are truncated to time.Minute | ||
if newDeadline == build.Deadline { | ||
// Disallow updates within than one minute | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if withinDuration(newDeadline, build.Deadline, time.Minute) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: it's an edge case, but it doesn't make sense to allow this. |
||
code = http.StatusNotModified | ||
return nil | ||
} | ||
|
@@ -839,3 +839,12 @@ func convertSQLNullInt64(i sql.NullInt64) *time.Duration { | |
|
||
return (*time.Duration)(&i.Int64) | ||
} | ||
|
||
func withinDuration(t1, t2 time.Time, d time.Duration) bool { | ||
dt := t1.Sub(t2) | ||
if dt < -d || dt > d { | ||
return false | ||
} | ||
Comment on lines
+845
to
+847
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: I just lifted this from |
||
|
||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review: I decided to stop truncating this as the consistency didn't seem worth losing the fidelity in other places. In the worst case, we'll stop a little bit later (but not too early).