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:
parent
f65c5778a9
commit
20a9a8c758
|
@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue