Skip to content

Commit 141cba9

Browse files
committed
Never reduce the deadline
1 parent 7bd2123 commit 141cba9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

coderd/database/queries/activitybump.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ WITH latest AS (
1818
-- workspace auto started at the given time and the original
1919
-- TTL was applied.
2020
WHEN NOW() + ('60 minutes')::interval > @next_autostart :: timestamptz
21-
-- If the autostart is behind the created_at, then the
21+
-- If the autostart is behind now(), then the
2222
-- autostart schedule is either the 0 time and not provided,
2323
-- or it was the autostart in the past, which is no longer
2424
-- relevant. If a past autostart is being passed in,
2525
-- that is a mistake by the caller.
26-
AND @next_autostart > workspace_builds.created_at
26+
AND @next_autostart > NOW()
2727
THEN
2828
-- Extend to the autostart, then add the TTL
2929
((@next_autostart :: timestamptz) - NOW()) + CASE
@@ -54,8 +54,9 @@ SET
5454
updated_at = NOW(),
5555
deadline = CASE
5656
WHEN l.build_max_deadline = '0001-01-01 00:00:00+00'
57-
THEN NOW() + l.ttl_interval
58-
ELSE LEAST(NOW() + l.ttl_interval, l.build_max_deadline)
57+
-- Never reduce the deadline from activity.
58+
THEN GREATEST(wb.deadline, NOW() + l.ttl_interval)
59+
ELSE LEAST(GREATEST(wb.deadline, NOW() + l.ttl_interval), l.build_max_deadline)
5960
END
6061
FROM latest l
6162
WHERE wb.id = l.build_id

0 commit comments

Comments
 (0)