diff --git a/pkg/repository/sqlcv1/concurrency.sql b/pkg/repository/sqlcv1/concurrency.sql index 0fe1e1e562..8737edd8a8 100644 --- a/pkg/repository/sqlcv1/concurrency.sql +++ b/pkg/repository/sqlcv1/concurrency.sql @@ -155,7 +155,7 @@ WITH eligible_slots_per_group AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = @tenantId::uuid AND wcs_all.strategy_id = @strategyId::bigint - ORDER BY wcs_all.priority DESC, wcs_all.sort_id ASC + ORDER BY wcs_all.is_filled DESC, wcs_all.priority DESC, wcs_all.sort_id ASC LIMIT @maxRuns::int ) wsc ON true ), eligible_slots AS ( @@ -206,7 +206,7 @@ WITH eligible_slots_per_group AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = @tenantId::uuid AND wcs_all.strategy_id = @strategyId::bigint - ORDER BY wcs_all.sort_id ASC + ORDER BY wcs_all.is_filled DESC, wcs_all.sort_id ASC LIMIT @maxRuns::int ) cs ON true ), schedule_timeout_slots AS ( @@ -329,7 +329,7 @@ WITH locked_workflow_concurrency_slots AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = @tenantId::uuid AND wcs_all.strategy_id = @strategyId::bigint - ORDER BY wcs_all.sort_id DESC + ORDER BY wcs_all.is_filled DESC, wcs_all.sort_id DESC LIMIT @maxRuns::int ) wsc ON true ), slots_to_run AS ( @@ -569,7 +569,7 @@ WITH locked_workflow_concurrency_slots AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = @tenantId::uuid AND wcs_all.strategy_id = @strategyId::bigint - ORDER BY wcs_all.sort_id ASC + ORDER BY wcs_all.is_filled DESC, wcs_all.sort_id ASC LIMIT @maxRuns::int ) wsc ON true ), slots_to_run AS ( diff --git a/pkg/repository/sqlcv1/concurrency.sql.go b/pkg/repository/sqlcv1/concurrency.sql.go index 289204b2a1..d9fba61bcc 100644 --- a/pkg/repository/sqlcv1/concurrency.sql.go +++ b/pkg/repository/sqlcv1/concurrency.sql.go @@ -756,7 +756,7 @@ WITH eligible_slots_per_group AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = $1::uuid AND wcs_all.strategy_id = $2::bigint - ORDER BY wcs_all.sort_id ASC + ORDER BY wcs_all.is_filled DESC, wcs_all.sort_id ASC LIMIT $3::int ) cs ON true ), schedule_timeout_slots AS ( @@ -928,7 +928,7 @@ WITH locked_workflow_concurrency_slots AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = $1::uuid AND wcs_all.strategy_id = $2::bigint - ORDER BY wcs_all.sort_id DESC + ORDER BY wcs_all.is_filled DESC, wcs_all.sort_id DESC LIMIT $3::int ) wsc ON true ), slots_to_run AS ( @@ -1013,7 +1013,7 @@ WITH locked_workflow_concurrency_slots AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = $1::uuid AND wcs_all.strategy_id = $2::bigint - ORDER BY wcs_all.sort_id ASC + ORDER BY wcs_all.is_filled DESC, wcs_all.sort_id ASC LIMIT $3::int ) wsc ON true ), slots_to_run AS ( @@ -1085,7 +1085,7 @@ WITH eligible_slots_per_group AS ( wcs_all.key = distinct_keys.key AND wcs_all.tenant_id = $1::uuid AND wcs_all.strategy_id = $2::bigint - ORDER BY wcs_all.priority DESC, wcs_all.sort_id ASC + ORDER BY wcs_all.is_filled DESC, wcs_all.priority DESC, wcs_all.sort_id ASC LIMIT $3::int ) wsc ON true ), eligible_slots AS (