fix: Added a small timeout to the runNow() script scheduler

This is to avoid a small race conditions in the tests, where a script has signalled that it's finished loading but the schedular has not started waiting for the next task.
This commit is contained in:
Leon Mika 2023-07-03 11:24:16 +10:00
parent f65c5778a9
commit 20a9a8c758

View file

@ -3,6 +3,7 @@ package scriptmanager
import ( import (
"context" "context"
"github.com/pkg/errors" "github.com/pkg/errors"
"time"
) )
type scriptScheduler struct { type scriptScheduler struct {
@ -41,7 +42,7 @@ func (ss *scriptScheduler) runNow(ctx context.Context, job func(ctx context.Cont
select { select {
case ss.jobChan <- scriptJob{ctx: ctx, job: job}: case ss.jobChan <- scriptJob{ctx: ctx, job: job}:
return nil return nil
default: case <-time.After(500 * time.Millisecond):
return errors.New("a script is already running") return errors.New("a script is already running")
} }
} }