MCPcopy Create free account
hub / github.com/cloudbase/garm / startLoopForFunction

Method startLoopForFunction

runner/pool/pool.go:498–550  ·  view source on GitHub ↗
(f func() error, interval time.Duration, name string, alwaysRun bool)

Source from the content-addressed store, hash-verified

496}
497
498func (r *basePoolManager) startLoopForFunction(f func() error, interval time.Duration, name string, alwaysRun bool) {
499 slog.InfoContext(
500 r.ctx, "starting loop for entity",
501 "loop_name", name)
502 ticker := time.NewTicker(interval)
503 r.wg.Add(1)
504
505 defer func() {
506 slog.InfoContext(
507 r.ctx, "pool loop exited",
508 "loop_name", name)
509 ticker.Stop()
510 r.wg.Done()
511 }()
512
513 for {
514 shouldRun := r.managerIsRunning
515 if alwaysRun {
516 shouldRun = true
517 }
518 switch shouldRun {
519 case true:
520 select {
521 case <-ticker.C:
522 if err := f(); err != nil {
523 slog.With(slog.Any("error", err)).ErrorContext(
524 r.ctx, "error in loop",
525 "loop_name", name)
526 if errors.Is(err, runnerErrors.ErrUnauthorized) {
527 r.SetPoolRunningState(false, err.Error())
528 }
529 }
530 case <-r.ctx.Done():
531 // daemon is shutting down.
532 return
533 case <-r.quit:
534 // this worker was stopped.
535 return
536 }
537 default:
538 select {
539 case <-r.ctx.Done():
540 // daemon is shutting down.
541 return
542 case <-r.quit:
543 // this worker was stopped.
544 return
545 default:
546 r.waitForTimeoutOrCancelled(common.BackoffTimer)
547 }
548 }
549 }
550}
551
552func (r *basePoolManager) updateTools() error {
553 tools, err := cache.GetGithubToolsCache(r.entity.ID)

Callers 1

StartMethod · 0.95

Calls 6

SetPoolRunningStateMethod · 0.95
AddMethod · 0.80
StopMethod · 0.65
DoneMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected