Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runner/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,9 @@ func (r *basePoolManager) deleteInstanceFromProvider(ctx context.Context, instan
}

func (r *basePoolManager) sleepWithCancel(sleepTime time.Duration) (canceled bool) {
if sleepTime == 0 {
return false
}
ticker := time.NewTicker(sleepTime)
defer ticker.Stop()

Expand Down
3 changes: 3 additions & 0 deletions workers/cache/tool_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (t *toolsUpdater) Reset() {
}

func (t *toolsUpdater) sleepWithCancel(sleepTime time.Duration) (canceled bool) {
if sleepTime == 0 {
return false
}
ticker := time.NewTicker(sleepTime)
defer ticker.Stop()

Expand Down
8 changes: 4 additions & 4 deletions workers/scaleset/scaleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ func (w *Worker) loop() {
}

func (w *Worker) sleepWithCancel(sleepTime time.Duration) (canceled bool) {
if sleepTime == 0 {
return false
}
ticker := time.NewTicker(sleepTime)
defer ticker.Stop()

Expand Down Expand Up @@ -663,10 +666,7 @@ Loop:
}
continue
}
// noop if already started. If the scaleset was just enabled, we need to
// start the listener here, or the <-w.listener.Wait() channel receive bellow
// will block forever, even if we start the listener, as a nil channel will
// block forever.
// noop if already started.
if err := w.listener.Start(); err != nil {
slog.ErrorContext(w.ctx, "error starting listener", "error", err, "consumer_id", w.consumerID)
if canceled := w.sleepWithCancel(2 * time.Second); canceled {
Expand Down
10 changes: 7 additions & 3 deletions workers/scaleset/scaleset_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/cloudbase/garm/util/github/scalesets"
)

var closed = make(chan struct{})

func init() { close(closed) }

func newListener(ctx context.Context, scaleSetHelper scaleSetHelper) *scaleSetListener {
return &scaleSetListener{
ctx: ctx,
Expand Down Expand Up @@ -278,11 +282,11 @@ func (l *scaleSetListener) loop() {

func (l *scaleSetListener) Wait() <-chan struct{} {
l.mux.Lock()
defer l.mux.Unlock()

if !l.running {
slog.DebugContext(l.ctx, "scale set listener is not running")
l.mux.Unlock()
return nil
return closed
}
l.mux.Unlock()
return l.loopExited
}
Loading