timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.13k stars 158 forks source link

Add sql function for publishing a new job from within postgres #251

Closed rattrayalex closed 3 years ago

rattrayalex commented 3 years ago

I'd like to be able to set up a TRIGGER and publish a new job within that. For example, when a given column changes from A to B, publish a job so that I can send an email.

With graphile-worker, this can be accomplished like so from within a pl/sql trigger function:

SELECT graphile_worker.add_job('update', json_build_object('id', id));

Similar functionality within pg-boss might be nice for use-cases like mine.

timgit commented 3 years ago

I have a few integrations currently in my app where I insert directly into the job table. Direct table access is in the docs and this should be straightforward for most use cases. Try a direct insert in your trigger first to see if that accomplished what you need.

rattrayalex commented 3 years ago

Ah, sorry, I missed the "Usage" link at the bottom of the README!