Sleep Scheduler: don't overwrite error
status from Worker
The Sleep Scheduler shouldn't push a Worker out of `error` status, as that could hide problematic situations.
This commit is contained in:
parent
d553ca5ab9
commit
48f081e03e
@ -17,6 +17,11 @@ import (
|
||||
// Time period for checking the schedule of every worker.
|
||||
const checkInterval = 1 * time.Minute
|
||||
|
||||
// skipWorkersInStatus has those worker statuses that should never be changed by the sleep scheduler.
|
||||
var skipWorkersInStatus = map[api.WorkerStatus]bool{
|
||||
api.WorkerStatusError: true,
|
||||
}
|
||||
|
||||
// SleepScheduler manages wake/sleep cycles of Workers.
|
||||
type SleepScheduler struct {
|
||||
clock clock.Clock
|
||||
@ -111,6 +116,10 @@ func (ss *SleepScheduler) ApplySleepSchedule(ctx context.Context, schedule *pers
|
||||
worker = schedule.Worker
|
||||
}
|
||||
|
||||
if !ss.mayUpdateWorker(worker) {
|
||||
return nil
|
||||
}
|
||||
|
||||
scheduled := ss.scheduledWorkerStatus(schedule)
|
||||
if scheduled == "" ||
|
||||
(worker.StatusRequested == scheduled && !worker.LazyStatusRequest) ||
|
||||
@ -208,3 +217,9 @@ func (ss *SleepScheduler) checkSchedule(ctx context.Context, schedule *persisten
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// mayUpdateWorker determines whether the sleep scheduler is allowed to update this Worker.
|
||||
func (ss *SleepScheduler) mayUpdateWorker(worker *persistence.Worker) bool {
|
||||
shouldSkip := skipWorkersInStatus[worker.Status]
|
||||
return !shouldSkip
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ func TestApplySleepSchedule(t *testing.T) {
|
||||
testForExpectedStatus(api.WorkerStatusAsleep)
|
||||
}
|
||||
|
||||
func TestApplySleepScheduleAlreadyCorrectStatus(t *testing.T) {
|
||||
func TestApplySleepScheduleNoStatusChange(t *testing.T) {
|
||||
ss, mocks, ctx := testFixtures(t)
|
||||
|
||||
worker := persistence.Worker{
|
||||
@ -219,6 +219,12 @@ func TestApplySleepScheduleAlreadyCorrectStatus(t *testing.T) {
|
||||
worker.StatusRequested = api.WorkerStatusAsleep
|
||||
worker.LazyStatusRequest = false
|
||||
runTest()
|
||||
|
||||
// Current status is not the right one, but error state should not be overwrittne.
|
||||
worker.Status = api.WorkerStatusError
|
||||
worker.StatusRequested = ""
|
||||
worker.LazyStatusRequest = false
|
||||
runTest()
|
||||
}
|
||||
|
||||
type TestMocks struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user