diff --git a/.sqlx/query-7b00baf2d4fb4d803f5958c01da30f10f372a0b52286226e763c95975f22ca6b.json b/.sqlx/query-2cf8e3335cff09bbdc0bcc0f292e167aa4df035772520a1243c5b5f4ee463bea.json similarity index 60% rename from .sqlx/query-7b00baf2d4fb4d803f5958c01da30f10f372a0b52286226e763c95975f22ca6b.json rename to .sqlx/query-2cf8e3335cff09bbdc0bcc0f292e167aa4df035772520a1243c5b5f4ee463bea.json index bc95aaa..270981d 100644 --- a/.sqlx/query-7b00baf2d4fb4d803f5958c01da30f10f372a0b52286226e763c95975f22ca6b.json +++ b/.sqlx/query-2cf8e3335cff09bbdc0bcc0f292e167aa4df035772520a1243c5b5f4ee463bea.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n WITH selected AS (\n SELECT id\n FROM durable.task\n WHERE (state IN ('ready', 'active') AND running_on IS NULL)\n OR (state = 'ready' AND running_on = $1)\n FOR UPDATE SKIP LOCKED\n LIMIT $2\n )\n UPDATE durable.task\n SET running_on = $1,\n state = 'active'\n FROM selected\n WHERE selected.id = task.id\n RETURNING\n task.id as id,\n task.name as name,\n task.wasm as \"wasm!\",\n task.data as \"data!: Json>\"\n ", + "query": "\n WITH selected AS (\n SELECT id\n FROM durable.task\n WHERE (state IN ('ready', 'active') AND running_on IS NULL)\n OR (state = 'ready' AND running_on = $1)\n ORDER BY id ASC\n FOR NO KEY UPDATE SKIP LOCKED\n LIMIT $2\n )\n UPDATE durable.task\n SET running_on = $1,\n state = 'active'\n FROM selected\n WHERE selected.id = task.id\n RETURNING\n task.id as id,\n task.name as name,\n task.wasm as \"wasm!\",\n task.data as \"data!: Json>\"\n ", "describe": { "columns": [ { @@ -37,5 +37,5 @@ false ] }, - "hash": "7b00baf2d4fb4d803f5958c01da30f10f372a0b52286226e763c95975f22ca6b" + "hash": "2cf8e3335cff09bbdc0bcc0f292e167aa4df035772520a1243c5b5f4ee463bea" } diff --git a/crates/durable-runtime/src/worker.rs b/crates/durable-runtime/src/worker.rs index 870e3c7..b72332f 100644 --- a/crates/durable-runtime/src/worker.rs +++ b/crates/durable-runtime/src/worker.rs @@ -778,7 +778,8 @@ impl Worker { FROM durable.task WHERE (state IN ('ready', 'active') AND running_on IS NULL) OR (state = 'ready' AND running_on = $1) - FOR UPDATE SKIP LOCKED + ORDER BY id ASC + FOR NO KEY UPDATE SKIP LOCKED LIMIT $2 ) UPDATE durable.task