@@ -11,7 +11,7 @@ import (
11
11
"github.com/coder/coder/codersdk"
12
12
)
13
13
14
- var AgentShuttingDown = xerrors .New ("agent is shutting down" )
14
+ var errAgentShuttingDown = xerrors .New ("agent is shutting down" )
15
15
16
16
type AgentOptions struct {
17
17
FetchInterval time.Duration
@@ -25,8 +25,12 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
25
25
if opts .FetchInterval == 0 {
26
26
opts .FetchInterval = 500 * time .Millisecond
27
27
}
28
- if opts .Wait && opts .FetchLogs == nil {
29
- return xerrors .Errorf ("fetch logs required when waiting for agent" )
28
+ if opts .FetchLogs == nil {
29
+ opts .FetchLogs = func (_ context.Context , _ uuid.UUID , _ int64 , _ bool ) (<- chan []codersdk.WorkspaceAgentStartupLog , io.Closer , error ) {
30
+ c := make (chan []codersdk.WorkspaceAgentStartupLog )
31
+ close (c )
32
+ return c , closeFunc (func () error { return nil }), nil
33
+ }
30
34
}
31
35
32
36
type fetchAgent struct {
@@ -112,7 +116,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
112
116
// It doesn't matter if we're connected or not, if the agent is
113
117
// shutting down, we don't know if it's coming back.
114
118
if agent .LifecycleState .ShuttingDown () {
115
- return AgentShuttingDown
119
+ return errAgentShuttingDown
116
120
}
117
121
118
122
switch agent .Status {
@@ -123,10 +127,6 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
123
127
}
124
128
125
129
case codersdk .WorkspaceAgentConnected :
126
- if opts .FetchLogs == nil {
127
- // Only agent connection status was requested.
128
- return nil
129
- }
130
130
if ! showStartupLogs && agent .LifecycleState == codersdk .WorkspaceAgentLifecycleReady {
131
131
// The workspace is ready, there's nothing to do but connect.
132
132
return nil
@@ -209,7 +209,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
209
209
// We no longer know if the startup script failed or not,
210
210
// but we need to tell the user something.
211
211
sw .Complete (stage , agent .ReadyAt .Sub (* agent .StartedAt ))
212
- return AgentShuttingDown
212
+ return errAgentShuttingDown
213
213
}
214
214
}
215
215
0 commit comments