Created
February 3, 2018 08:20
-
-
Save Gurpartap/7f567bc921a4dcd1ffaf1e0c23fd9ac8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
operation.* | |
FROM | |
operations operation | |
LEFT JOIN LATERAL ( | |
SELECT | |
_r.state | |
FROM | |
operations_results _r | |
WHERE | |
_r.operation_id = operation.id | |
ORDER BY | |
_r.created_at DESC | |
LIMIT | |
1 | |
) result ON TRUE | |
WHERE | |
operation.run_after <= now()::timestamptz | |
AND operation.name = $1::text | |
AND operation.queue = coalesce($2, '')::text | |
AND (result IS NULL OR result.state NOT IN ('completed', 'failed')) | |
ORDER BY | |
operation.priority DESC, | |
operation.run_after | |
LIMIT | |
1 | |
FOR NO KEY UPDATE OF | |
operation | |
SKIP LOCKED | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment