Skip to content

Commit

Permalink
Update SortFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
severinson committed Feb 28, 2024
1 parent 9487e35 commit fcdd3b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/scheduler/jobiteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (repo *InMemoryJobRepository) EnqueueMany(jctxs []*schedulercontext.JobSche

// sortQueue sorts jobs in a specified queue by the order in which they should be scheduled.
func (repo *InMemoryJobRepository) sortQueue(queue string) {
slices.SortFunc(repo.jctxsByQueue[queue], func(a, b *schedulercontext.JobSchedulingContext) bool {
return a.Job.SchedulingOrderCompare(b.Job) == -1
slices.SortFunc(repo.jctxsByQueue[queue], func(a, b *schedulercontext.JobSchedulingContext) int {
return a.Job.SchedulingOrderCompare(b.Job)
})
}

Expand Down
10 changes: 8 additions & 2 deletions internal/scheduler/preempting_queue_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,14 @@ func TestPreemptingQueueScheduler(t *testing.T) {
// which jobs are preempted).
slices.SortFunc(
result.ScheduledJobs,
func(a, b *schedulercontext.JobSchedulingContext) bool {
return a.Job.GetSubmitTime().Before(b.Job.GetSubmitTime())
func(a, b *schedulercontext.JobSchedulingContext) int {
if a.Job.GetSubmitTime().Before(b.Job.GetSubmitTime()) {
return -1
} else if b.Job.GetSubmitTime().Before(a.Job.GetSubmitTime()) {
return 1
} else {
return 0
}
},
)
var scheduledJobs []*jobdb.Job
Expand Down

0 comments on commit fcdd3b3

Please sign in to comment.