improve slightly concurrency run min started_at query

This commit is contained in:
Ruben Fiszel
2024-07-27 12:41:01 +02:00
parent ec9aad4dae
commit 2b67fbcd98
3 changed files with 3 additions and 1 deletions
@@ -0,0 +1 @@
-- Add down migration script here
@@ -0,0 +1 @@
CREATE INDEX IF NOT EXISTS queue_concurrency_started_at ON queue (workspace_id, script_path, started_at) WHERE concurrent_limit > 0 AND running = true AND job_kind != 'dependencies' AND canceled = false;-- Add up migration script here
+1 -1
View File
@@ -1761,7 +1761,7 @@ pub async fn pull<R: rsmq_async::RsmqConnection + Send + Clone>(
let min_started_at = sqlx::query!(
"SELECT COALESCE((SELECT MIN(started_at) as min_started_at
FROM queue
WHERE script_path = $1 AND job_kind != 'dependencies' AND running = true AND workspace_id = $2 AND canceled = false), $3) as min_started_at, now() AS now",
WHERE script_path = $1 AND job_kind != 'dependencies' AND running = true AND workspace_id = $2 AND canceled = false AND concurrent_limit > 0), $3) as min_started_at, now() AS now",
job_script_path,
&pulled_job.workspace_id,
completed_count.max_ended_at