MCPcopy Index your code
hub / github.com/coder/coder / apply

Method apply

provisionerd/runner/apply.go:12–64  ·  view source on GitHub ↗
(ctx context.Context, stage string, req *sdkproto.ApplyRequest)

Source from the content-addressed store, hash-verified

10)
11
12func (r *Runner) apply(ctx context.Context, stage string, req *sdkproto.ApplyRequest) (
13 *sdkproto.ApplyComplete, *proto.FailedJob,
14) {
15 // use the notStopped so that if we attempt to gracefully cancel, the stream
16 // will still be available for us to send the cancel to the provisioner
17 err := r.session.Send(&sdkproto.Request{Type: &sdkproto.Request_Apply{Apply: req}})
18 if err != nil {
19 return nil, r.failedWorkspaceBuildf("start provision: %s", err)
20 }
21 nevermind := make(chan struct{})
22 defer close(nevermind)
23 go func() {
24 select {
25 case <-nevermind:
26 return
27 case <-r.notStopped.Done():
28 return
29 case <-r.notCanceled.Done():
30 _ = r.session.Send(&sdkproto.Request{
31 Type: &sdkproto.Request_Cancel{
32 Cancel: &sdkproto.CancelRequest{},
33 },
34 })
35 }
36 }()
37
38 for {
39 msg, err := r.session.Recv()
40 if err != nil {
41 return nil, r.failedWorkspaceBuildf("recv workspace provision: %s", err)
42 }
43 switch msgType := msg.Type.(type) {
44 case *sdkproto.Response_Log:
45 r.logProvisionerJobLog(context.Background(), msgType.Log.Level, "workspace provisioner job logged",
46 slog.F("level", msgType.Log.Level),
47 slog.F("output", msgType.Log.Output),
48 slog.F("workspace_build_id", r.job.GetWorkspaceBuild().WorkspaceBuildId),
49 )
50
51 r.queueLog(ctx, &proto.Log{
52 Source: proto.LogSource_PROVISIONER,
53 Level: msgType.Log.Level,
54 CreatedAt: time.Now().UnixMilli(),
55 Output: msgType.Log.Output,
56 Stage: stage,
57 })
58 case *sdkproto.Response_Apply:
59 return msgType.Apply, nil
60 default:
61 return nil, r.failedJobf("unexpected plan response type %T", msg.Type)
62 }
63 }
64}

Callers 2

runWorkspaceBuildMethod · 0.95
ApplyMethod · 0.45

Calls 8

failedWorkspaceBuildfMethod · 0.95
logProvisionerJobLogMethod · 0.95
queueLogMethod · 0.95
failedJobfMethod · 0.95
SendMethod · 0.65
RecvMethod · 0.65
DoneMethod · 0.45
GetWorkspaceBuildMethod · 0.45

Tested by 1

ApplyMethod · 0.36