Skip to content

Commit

Permalink
fix: dont schedule already-scheduled runs at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Jan 21, 2025
1 parent 3145733 commit 91cf7a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 8 additions & 1 deletion internal/run/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ func (q queue) process(run *Run) (qq queue, enqueuePlan bool, unlock bool) {
unlock = true
}
} else {
// check if run is in backlog
if q.current == nil && run.Status != RunPending && !run.Done() {
// This condition handles the scenario where the scheduler has
// only been started up and the scheduler has not yet set the
// current run and there is an existing scheduled run that is
// not yet done.
q.current = &run.ID
return q, false, false
}
var found bool
for i, id := range q.backlog {
if run.ID == id {
Expand Down
12 changes: 10 additions & 2 deletions internal/run/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,21 @@ func TestScheduler_process(t *testing.T) {
false,
},
{
"make run current and request enqueue plan",
"make pending run current and request enqueue plan",
queue{},
&Run{ID: runID1},
&Run{ID: runID1, Status: RunPending},
queue{current: &runID1},
true,
false,
},
{
"make plan_enqueued run current and do not request enqueue plan",
queue{},
&Run{ID: runID1, Status: RunPlanQueued},
queue{current: &runID1},
false,
false,
},
{
"move backlogged run into current and request enqueue plan",
queue{backlog: []resource.ID{runID1}},
Expand Down

0 comments on commit 91cf7a1

Please sign in to comment.