Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent db error if no async calls to execute (#2081)
When a controller tries to get a lease on the next async call to execute, the lease creation code should first check to see if there was a call found. Before when a controller tried to get a hold on the next async call to execute, it would result in this error: ``` 2024-07-15 16:00:08 UTC:10.2.111.21(46692):adminuser@tbd:[60308]:ERROR: null value in column "key" of relation "leases" violates not-null constraint 2024-07-15 16:00:08 UTC:10.2.111.21(46692):adminuser@tbd:[60308]:DETAIL: Failing row contains (1632753, 37a8d114-73ca-46a1-b03b-a17331d17181, null, 2024-07-15 16:00:08.260772+00, 2024-07-15 16:00:13.260772+00, null). 2024-07-15 16:00:08 UTC:10.2.111.21(46692):adminuser@tbd:[60308]:STATEMENT: -- name: AcquireAsyncCall :one WITH async_call AS ( SELECT id FROM async_calls WHERE state = 'pending' AND scheduled_at <= (NOW() AT TIME ZONE 'utc') LIMIT 1 FOR UPDATE SKIP LOCKED ), lease AS ( INSERT INTO leases (idempotency_key, key, expires_at) VALUES (gen_random_uuid(), '/system/async_call/' || (SELECT id FROM async_call), (NOW() AT TIME ZONE 'utc') + $1::interval) RETURNING id, idempotency_key, key, created_at, expires_at, metadata ) UPDATE async_calls SET state = 'executing', lease_id = (SELECT id FROM lease) WHERE id = (SELECT id FROM async_call) RETURNING id AS async_call_id, (SELECT idempotency_key FROM lease) AS lease_idempotency_key, (SELECT key FROM lease) AS lease_key, origin, verb, request, scheduled_at, remaining_attempts, backoff, max_backoff ```
- Loading branch information