timgit / pg-boss

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

stop() blocks calls to publish() #283

Closed amc6 closed 2 years ago

amc6 commented 2 years ago

It appears that calling pgboss.stop() causes subsequent calls to publish() to fail.

In my use case, I want to be able to stop running new jobs when we know that the old instance is being destroyed during a deployment. But jobs already in progress should be allowed to complete, and some of them publish new jobs. The graceful flags allows these jobs to keep running, but they are still prevented from publishing. Continuing to publish should be safe as long as it doesn't start new jobs on the stopping instance.

For now, I've worked around this issue by instead just unsubscribing from every subscription instead of calling stop(). But this requires more bookkeeping, and I would imagine my use-case may be common. Thanks!

timgit commented 2 years ago

This was intentional, but primarily not for this use case. The current logic is "if start() hasn't been called, then how do we know the schema has been installed?" This is safe to do only after start() has been called. We could introduce a new state bool on start to indicate it's safe to call publish() and insert()

amc6 commented 2 years ago

Yeah that makes sense. Thanks!