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

Commit22cd000

Browse files
committed
refactor: workspace: autostop_schedule -> ttl
1 parent8814cb0 commit22cd000

23 files changed

+311
-417
lines changed

‎cli/autostop.go‎

Lines changed: 0 additions & 167 deletions
This file was deleted.

‎cli/list.go‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func list() *cobra.Command {
5050
}
5151

5252
tableWriter:=cliui.Table()
53-
header:= table.Row{"workspace","template","status","last built","outdated","autostart","autostop"}
53+
header:= table.Row{"workspace","template","status","last built","outdated","autostart","ttl"}
5454
tableWriter.AppendHeader(header)
5555
tableWriter.SortBy([]table.SortBy{{
5656
Name:"workspace",
@@ -117,10 +117,8 @@ func list() *cobra.Command {
117117
}
118118

119119
autostopDisplay:="-"
120-
ifworkspace.AutostopSchedule!="" {
121-
ifsched,err:=schedule.Weekly(workspace.AutostopSchedule);err==nil {
122-
autostopDisplay=sched.Cron()
123-
}
120+
ifworkspace.TTL!=nil {
121+
autostopDisplay=workspace.TTL.String()
124122
}
125123

126124
user:=usersByID[workspace.OwnerID]

‎cli/root.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func Root() *cobra.Command {
6262

6363
cmd.AddCommand(
6464
autostart(),
65-
autostop(),
6665
configSSH(),
6766
create(),
6867
delete(),
@@ -78,6 +77,7 @@ func Root() *cobra.Command {
7877
stop(),
7978
ssh(),
8079
templates(),
80+
ttl(),
8181
update(),
8282
users(),
8383
portForward(),

‎cli/ssh.go‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/coder/coder/cli/cliflag"
2222
"github.com/coder/coder/cli/cliui"
2323
"github.com/coder/coder/coderd/autobuild/notify"
24-
"github.com/coder/coder/coderd/autobuild/schedule"
2524
"github.com/coder/coder/coderd/database"
2625
"github.com/coder/coder/codersdk"
2726
"github.com/coder/coder/cryptorand"
@@ -271,16 +270,11 @@ func notifyCondition(ctx context.Context, client *codersdk.Client, workspaceID u
271270
return time.Time{},nil
272271
}
273272

274-
ifws.AutostopSchedule=="" {
273+
ifws.TTL==nil {
275274
return time.Time{},nil
276275
}
277276

278-
sched,err:=schedule.Weekly(ws.AutostopSchedule)
279-
iferr!=nil {
280-
return time.Time{},nil
281-
}
282-
283-
deadline=sched.Next(now)
277+
deadline=now.Add(*ws.TTL)
284278
callback=func() {
285279
ttl:=deadline.Sub(now)
286280
vartitle,bodystring

‎cli/ttl.go‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/coder/coder/codersdk"
10+
)
11+
12+
constttlDescriptionLong=`To have your workspace stop automatically after a configurable interval has passed.`
13+
14+
functtl()*cobra.Command {
15+
ttlCmd:=&cobra.Command{
16+
Annotations:workspaceCommand,
17+
Use:"ttl enable <workspace>",
18+
Short:"schedule a workspace to automatically stop after a configurable interval",
19+
Long:ttlDescriptionLong,
20+
Example:"coder ttl enable my-workspace 8h30m",
21+
}
22+
23+
ttlCmd.AddCommand(ttlShow())
24+
ttlCmd.AddCommand(ttlEnable())
25+
ttlCmd.AddCommand(ttlDisable())
26+
27+
returnttlCmd
28+
}
29+
30+
functtlShow()*cobra.Command {
31+
cmd:=&cobra.Command{
32+
Use:"show <workspace_name>",
33+
Args:cobra.ExactArgs(1),
34+
RunE:func(cmd*cobra.Command,args []string)error {
35+
client,err:=createClient(cmd)
36+
iferr!=nil {
37+
returnerr
38+
}
39+
organization,err:=currentOrganization(cmd,client)
40+
iferr!=nil {
41+
returnerr
42+
}
43+
44+
workspace,err:=client.WorkspaceByOwnerAndName(cmd.Context(),organization.ID,codersdk.Me,args[0])
45+
iferr!=nil {
46+
returnerr
47+
}
48+
49+
ifworkspace.TTL==nil {
50+
_,_=fmt.Fprintf(cmd.OutOrStdout(),"not enabled\n")
51+
returnnil
52+
}
53+
54+
_,_=fmt.Fprintf(cmd.OutOrStdout(),"%s\n",workspace.TTL)
55+
56+
returnnil
57+
},
58+
}
59+
returncmd
60+
}
61+
62+
functtlEnable()*cobra.Command {
63+
cmd:=&cobra.Command{
64+
Use:"enable <workspace_name> <ttl>",
65+
Args:cobra.ExactArgs(2),
66+
RunE:func(cmd*cobra.Command,args []string)error {
67+
client,err:=createClient(cmd)
68+
iferr!=nil {
69+
returnerr
70+
}
71+
organization,err:=currentOrganization(cmd,client)
72+
iferr!=nil {
73+
returnerr
74+
}
75+
76+
workspace,err:=client.WorkspaceByOwnerAndName(cmd.Context(),organization.ID,codersdk.Me,args[0])
77+
iferr!=nil {
78+
returnerr
79+
}
80+
81+
ttl,err:=time.ParseDuration(args[1])
82+
iferr!=nil {
83+
returnerr
84+
}
85+
86+
err=client.UpdateWorkspaceTTL(cmd.Context(),workspace.ID, codersdk.UpdateWorkspaceTTLRequest{
87+
TTL:&ttl,
88+
})
89+
iferr!=nil {
90+
returnerr
91+
}
92+
93+
returnnil
94+
},
95+
}
96+
97+
returncmd
98+
}
99+
100+
functtlDisable()*cobra.Command {
101+
return&cobra.Command{
102+
Use:"disable <workspace_name>",
103+
Args:cobra.ExactArgs(1),
104+
RunE:func(cmd*cobra.Command,args []string)error {
105+
client,err:=createClient(cmd)
106+
iferr!=nil {
107+
returnerr
108+
}
109+
organization,err:=currentOrganization(cmd,client)
110+
iferr!=nil {
111+
returnerr
112+
}
113+
114+
workspace,err:=client.WorkspaceByOwnerAndName(cmd.Context(),organization.ID,codersdk.Me,args[0])
115+
iferr!=nil {
116+
returnerr
117+
}
118+
119+
err=client.UpdateWorkspaceTTL(cmd.Context(),workspace.ID, codersdk.UpdateWorkspaceTTLRequest{
120+
TTL:nil,
121+
})
122+
iferr!=nil {
123+
returnerr
124+
}
125+
126+
_,_=fmt.Fprintf(cmd.OutOrStdout(),"\nThe %s workspace will no longer automatically stop.\n\n",workspace.Name)
127+
128+
returnnil
129+
},
130+
}
131+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp