Skip to content

Commit ed328e4

Browse files
committed
fix: high priority pipelines could be starved by parallel/ label
1 parent 7165b5b commit ed328e4

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

backend/server/services/pipeline.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,28 @@ func dequeuePipeline(runningParallelLabels []string) (pipeline *models.Pipeline,
261261
}))
262262
// prepare query to find an appropriate pipeline to execute
263263
pipeline = &models.Pipeline{}
264+
// 1. find out the current highest priority in the queue
265+
top_priority := 0
266+
where_status := dal.Where("status IN ?", []string{models.TASK_CREATED, models.TASK_RERUN, models.TASK_RESUME})
267+
err = tx.First(&top_priority, dal.Select("priority"), dal.From(pipeline), where_status, dal.Orderby("priority DESC"))
268+
if err != nil {
269+
tx.Rollback()
270+
}
271+
// 2. pick the earlier runnable pipeline with the highest priority
264272
err = tx.First(pipeline,
265-
dal.Where("status IN ?", []string{models.TASK_CREATED, models.TASK_RERUN, models.TASK_RESUME}),
273+
where_status,
274+
dal.Where("priority = ?", top_priority),
266275
dal.Join(
267276
`left join _devlake_pipeline_labels ON
268277
_devlake_pipeline_labels.pipeline_id = _devlake_pipelines.id AND
269278
_devlake_pipeline_labels.name LIKE 'parallel/%' AND
270279
_devlake_pipeline_labels.name in ?`,
271280
runningParallelLabels,
272281
),
273-
dal.Groupby("priority, id"),
282+
dal.Groupby("id"),
274283
dal.Having("count(_devlake_pipeline_labels.name)=0"),
275284
dal.Select("id"),
276-
dal.Orderby("priority DESC, id ASC"),
285+
dal.Orderby("id ASC"),
277286
dal.Limit(1),
278287
)
279288
if err == nil {

0 commit comments

Comments
 (0)