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

Method Execute

agent/agentscripts/agentscripts.go:201–234  ·  view source on GitHub ↗

Execute runs a set of scripts according to a filter.

(ctx context.Context, option ExecuteOption)

Source from the content-addressed store, hash-verified

199
200// Execute runs a set of scripts according to a filter.
201func (r *Runner) Execute(ctx context.Context, option ExecuteOption) error {
202 initErr := func() error {
203 r.initMutex.Lock()
204 defer r.initMutex.Unlock()
205 if !r.initialized {
206 return xerrors.New("execute: not initialized")
207 }
208 return nil
209 }()
210 if initErr != nil {
211 return initErr
212 }
213
214 var eg errgroup.Group
215 for _, script := range r.scripts {
216 runScript := (option == ExecuteStartScripts && script.RunOnStart) ||
217 (option == ExecuteStopScripts && script.RunOnStop) ||
218 (option == ExecuteCronScripts && script.Cron != "") ||
219 option == ExecuteAllScripts
220
221 if !runScript {
222 continue
223 }
224
225 eg.Go(func() error {
226 err := r.trackRun(ctx, script, option)
227 if err != nil {
228 return xerrors.Errorf("run agent script %q: %w", script.LogSourceID, err)
229 }
230 return nil
231 })
232 }
233 return eg.Wait()
234}
235
236// trackRun wraps "run" with metrics.
237func (r *Runner) trackRun(ctx context.Context, script codersdk.WorkspaceAgentScript, option ExecuteOption) error {

Callers

nothing calls this directly

Calls 7

trackRunMethod · 0.95
GoMethod · 0.80
NewMethod · 0.65
WaitMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected