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

Commit4420985

Browse files
authored
feat(coderd): activity bump for full TTL instead of 1h (#5732)
1 parente558a25 commit4420985

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

‎coderd/activitybump.go‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,29 @@ func activityBumpWorkspace(log slog.Logger, db database.Store, workspaceID uuid.
4343
returnnil
4444
}
4545

46-
// We sent bumpThreshold slightly under bumpAmount to minimize DB writes.
47-
const (
48-
bumpAmount=time.Hour
49-
bumpThreshold=time.Hour- (time.Minute*10)
46+
workspace,err:=s.GetWorkspaceByID(ctx,workspaceID)
47+
iferr!=nil {
48+
returnxerrors.Errorf("get workspace: %w",err)
49+
}
50+
51+
var (
52+
// We bump by the original TTL to prevent counter-intuitive behavior
53+
// as the TTL wraps. For example, if I set the TTL to 12 hours, sign off
54+
// work at midnight, come back at 10am, I would want another full day
55+
// of uptime. In the prior implementation, the workspace would enter
56+
// a state of always expiring 1 hour in the future
57+
bumpAmount=time.Duration(workspace.Ttl.Int64)
58+
// DB writes are expensive so we only bump when 5% of the deadline
59+
// has elapsed.
60+
bumpEvery=bumpAmount/20
61+
timeSinceLastBump=bumpAmount-time.Until(build.Deadline)
5062
)
5163

52-
if!build.Deadline.Before(time.Now().Add(bumpThreshold)) {
64+
iftimeSinceLastBump<bumpEvery {
65+
returnnil
66+
}
67+
68+
ifbumpAmount==0 {
5369
returnnil
5470
}
5571

‎coderd/activitybump_test.go‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ func TestWorkspaceActivityBump(t *testing.T) {
1919

2020
ctx:=context.Background()
2121

22+
constttl=time.Minute
23+
2224
setupActivityTest:=func(t*testing.T) (client*codersdk.Client,workspace codersdk.Workspace,assertBumpedfunc(wantbool)) {
23-
varttlMillisint64=60*1000
25+
ttlMillis:=int64(ttl/time.Millisecond)
2426

2527
client=coderdtest.New(t,&coderdtest.Options{
26-
AppHostname:proxyTestSubdomainRaw,
27-
IncludeProvisionerDaemon:true,
28-
AgentStatsRefreshInterval:time.Millisecond*100,
29-
MetricsCacheRefreshInterval:time.Millisecond*100,
28+
AppHostname:proxyTestSubdomainRaw,
29+
IncludeProvisionerDaemon:true,
30+
// Agent stats trigger the activity bump, so we want to report
31+
// very frequently in tests.
32+
AgentStatsRefreshInterval:time.Millisecond*100,
3033
})
3134
user:=coderdtest.CreateFirstUser(t,client)
3235

@@ -67,11 +70,11 @@ func TestWorkspaceActivityBump(t *testing.T) {
6770
require.NoError(t,err)
6871
returnworkspace.LatestBuild.Deadline.Time!=firstDeadline
6972
},
70-
testutil.WaitShort,testutil.IntervalFast,
73+
testutil.WaitLong,testutil.IntervalFast,
7174
"deadline %v never updated",firstDeadline,
7275
)
7376

74-
require.WithinDuration(t,database.Now().Add(time.Hour),workspace.LatestBuild.Deadline.Time,3*time.Second)
77+
require.WithinDuration(t,database.Now().Add(ttl),workspace.LatestBuild.Deadline.Time,3*time.Second)
7578
}
7679
}
7780

@@ -87,6 +90,8 @@ func TestWorkspaceActivityBump(t *testing.T) {
8790
require.NoError(t,err)
8891
deferconn.Close()
8992

93+
// Must send network traffic after a few seconds to surpass bump threshold.
94+
time.Sleep(time.Second*3)
9095
sshConn,err:=conn.SSHClient(ctx)
9196
require.NoError(t,err)
9297
_=sshConn.Close()

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const Language = {
6262
ttlLabel:"Time until shutdown (hours)",
6363
ttlCausesShutdownHelperText:"Your workspace will shut down",
6464
ttlCausesShutdownAfterStart:
65-
"after its next start. We delay shutdown byan hour whenever we detect activity",
65+
"after its next start. We delay shutdown bythis time whenever we detect activity",
6666
ttlCausesNoShutdownHelperText:
6767
"Your workspace will not automatically shut down.",
6868
formTitle:"Workspace schedule",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp