-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reject requests when worker is down #47
Conversation
@@ -21,6 +21,25 @@ create table net.http_request_queue( | |||
|
|||
create index created_idx on net.http_request_queue (created); | |||
|
|||
create or replace function net._check_worker_is_up() returns trigger as $$ | |||
begin | |||
if not exists (select pid from pg_stat_activity where backend_type = 'pg_net worker') then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enforced the condition with SQL.
My original plan was updating a GUC with C in the worker(as mentioned on #44 (comment)), but using the DefineCustomBoolVariable()
plus SetConfigOption() didn't seem to work. So I just did it with SQL.
$$ language plpgsql; | ||
|
||
create trigger ensure_worker_is_up | ||
after insert on net.http_request_queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be before insert
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, this is correct 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in this case we don't care for the NEW/OLD values of the row(or not even the row for that matter) so an AFTER insert should do.
Helps with #45.
When the worker is down for any reason the request queue will now reject insertions.