-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use set of pop/set_vt * add sql migration * add pop and set_vt tests
- Loading branch information
Showing
5 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
DROP FUNCTION pgmq.set_vt(text, bigint, integer); | ||
CREATE FUNCTION pgmq.set_vt(queue_name TEXT, msg_id BIGINT, vt INTEGER) | ||
RETURNS SETOF pgmq.message_record AS $$ | ||
DECLARE | ||
sql TEXT; | ||
result pgmq.message_record; | ||
BEGIN | ||
sql := FORMAT( | ||
$QUERY$ | ||
UPDATE pgmq.q_%s | ||
SET vt = (now() + interval '%s seconds') | ||
WHERE msg_id = %s | ||
RETURNING *; | ||
$QUERY$, | ||
queue_name, vt, msg_id | ||
); | ||
RETURN QUERY EXECUTE sql; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
DROP FUNCTION pgmq.pop(text); | ||
CREATE FUNCTION pgmq.pop(queue_name TEXT) | ||
RETURNS SETOF pgmq.message_record AS $$ | ||
DECLARE | ||
sql TEXT; | ||
result pgmq.message_record; | ||
BEGIN | ||
sql := FORMAT( | ||
$QUERY$ | ||
WITH cte AS | ||
( | ||
SELECT msg_id | ||
FROM pgmq.q_%s | ||
WHERE vt <= now() | ||
ORDER BY msg_id ASC | ||
LIMIT 1 | ||
FOR UPDATE SKIP LOCKED | ||
) | ||
DELETE from pgmq.q_%s | ||
WHERE msg_id = (select msg_id from cte) | ||
RETURNING *; | ||
$QUERY$, | ||
queue_name, queue_name | ||
); | ||
RETURN QUERY EXECUTE sql; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains 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
This file contains 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