-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces a trigger which will notify a channel when tasks are inserted or updated in a "pending" state. Workers now listen on this channel and if their queue is named as the one the notification is for begin processing the next task. Because channel notifications can fail, we retain the polling mechanism only now it's set to a default polling interval of one minute. This can be configured to be shorter or longer as well. Closes #19
- Loading branch information
1 parent
a898a8d
commit 23adffa
Showing
2 changed files
with
157 additions
and
80 deletions.
There are no files selected for viewing
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,19 @@ | ||
-- function to notify about task changes | ||
create or replace function underway.task_change_notify() | ||
returns trigger as $$ | ||
begin | ||
if (new.state = 'pending') then | ||
perform pg_notify('task_change', json_build_object( | ||
'task_queue_name', new.task_queue_name | ||
)::text); | ||
end if; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql; | ||
|
||
-- trigger that calls the function after task changes | ||
create trigger task_changed | ||
after insert or update on underway.task | ||
for each row | ||
execute procedure underway.task_change_notify(); |
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