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

Function New

provisionerd/provisionerd.go:72–118  ·  view source on GitHub ↗

New creates and starts a provisioner daemon.

(clientDialer Dialer, opts *Options)

Source from the content-addressed store, hash-verified

70
71// New creates and starts a provisioner daemon.
72func New(clientDialer Dialer, opts *Options) *Server {
73 if opts == nil {
74 opts = &Options{}
75 }
76 if opts.UpdateInterval == 0 {
77 opts.UpdateInterval = 5 * time.Second
78 }
79 if opts.ForceCancelInterval == 0 {
80 opts.ForceCancelInterval = 10 * time.Minute
81 }
82 if opts.LogBufferInterval == 0 {
83 opts.LogBufferInterval = 250 * time.Millisecond
84 }
85 if opts.TracerProvider == nil {
86 opts.TracerProvider = trace.NewNoopTracerProvider()
87 }
88 if opts.Metrics == nil {
89 reg := prometheus.NewRegistry()
90 mets := NewMetrics(reg)
91 opts.Metrics = &mets
92 }
93 if opts.InitConnectionCh == nil {
94 opts.InitConnectionCh = make(chan struct{})
95 }
96
97 ctx, ctxCancel := context.WithCancel(context.Background())
98 daemon := &Server{
99 opts: opts,
100 tracer: opts.TracerProvider.Tracer(tracing.TracerName),
101
102 clientDialer: clientDialer,
103 clientCh: make(chan proto.DRPCProvisionerDaemonClient),
104
105 closeContext: ctx,
106 closeCancel: ctxCancel,
107 closedCh: make(chan struct{}),
108 shuttingDownCh: make(chan struct{}),
109 acquireDoneCh: make(chan struct{}),
110 initConnectionCh: opts.InitConnectionCh,
111 externalProvisioner: opts.ExternalProvisioner,
112 }
113
114 daemon.wg.Add(2)
115 go daemon.connect()
116 go daemon.acquireLoop()
117 return daemon
118}
119
120type Server struct {
121 opts *Options

Callers 6

createProvisionerdFunction · 0.92
newProvisionerDaemonFunction · 0.92

Calls 5

connectMethod · 0.95
acquireLoopMethod · 0.95
TracerMethod · 0.80
NewMetricsFunction · 0.70
AddMethod · 0.65

Tested by 2

createProvisionerdFunction · 0.74