-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Create jobs in the database using triggers #68
Comments
👍 I have defaults defined for most fields, so unless you need to change them, they can be excluded from COPY or INSERT. |
I've gone this route (queuing jobs via a trigger) and have had a great success with it. I use In case it's helpful to others, here's what I'm using: create or replace function dovetail_private.queuenoteforsearchindexing(note_id uuid) returns void as $$
insert into dovetail_pgboss.job (id, name, startin, singletonkey, data)
values
(
uuid_generate_v1(),
'SEARCH_INDEXING_INDEX_NOTE',
'10 seconds'::interval,
-- Using the note ID as the singletonkey serves to debounce based on note.
$1::text,
json_build_object('noteId', $1::text)
)
on conflict do nothing
$$ language sql strict security definer;
create function dovetail_private.note$queuesearchindexing() returns trigger as $$
begin
perform dovetail_private.queuenoteforsearchindexing(new.id);
-- result is ignored since this is an AFTER trigger
return null;
end;
$$ language plpgsql strict;
create trigger afterupdate050$queuesearchindexing after update
on dovetail.note
for each row
when (
new.title is distinct from old.title
or new.deleted is distinct from old.deleted
or new.type is distinct from old.type
or new.content_version is distinct from old.content_version
or new.ranges::text is distinct from old.ranges::text
)
execute procedure dovetail_private.note$queuesearchindexing(); |
I would like to create jobs from within the database and have boss workers process them (sending emails and such). Ideally, I would use a trigger on some table that creates the job (based on rules). Can I create a job with SQL in a trigger?
The text was updated successfully, but these errors were encountered: