How do you clear scheduled jobs?
I'd like to cancel a PgBoss job because I changed the logic, is there a way to clear it from the database?
2 Replies
Hi @wardbox. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To clear or cancel scheduled jobs in Wasp using PgBoss, you have a couple of options:
1. Cancel a specific job:
You can use the
cancel()
method provided by PgBoss. When you submit a job, you get back a SubmittedJob
instance which has a pgBoss.cancel()
method. This allows you to cancel a specific job. Here's how you can use it:
Wasp Docs - Jobs API Reference provides more details on this.
2. Remove scheduled jobs from the database:
If you've changed the logic or name of a job that had a schedule associated with it, PgBoss will continue scheduling those jobs but they will have no handlers associated. To resolve this, you can remove the applicable row from the schedule
table in the pgboss
schema of your database.
Wasp Docs - pg-boss considerations mentions this approach:
"If you change a name that had a schedule
associated with it, pg-boss will continue scheduling those jobs but they will have no handlers associated, and will thus become stale and expire. To resolve this, you can remove the applicable row from the schedule
table in the pgboss
schema of your database."
Remember, when you make changes to job logic or schedules, it's important to manage the existing scheduled jobs to prevent stale or unnecessary executions.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @wardbox, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Here's a piece of our internal API, I believe we should offer a better API, but this might do the trick, if you know the job ID
I believe you could use the
fetch
function to get the job by jobName (internally, we use the job name you defined in the Wasp file) and then you can cancel a job:
https://github.com/timgit/pg-boss/blob/8.4.2/docs/readme.mdGitHub
pg-boss/docs/readme.md at 8.4.2 · timgit/pg-boss
Queueing jobs in Postgres from Node.js like a boss - timgit/pg-boss