Replies: 1 comment 2 replies
-
Adding this logic inside your custom db adapter is probably the best way to handle this specific case in the worker, but other db use cases may require different "empty responses" and still fail and throw. Does Heroku provide a stop signal ahead of scheduled maintenance? If so, you could use that to gracefully stop pg-boss during the maintenance. You will need to use pg-boss v6 or higher for that. This is currently only published in beta, so let me know if that prevents you from using it. I am planning on merging this early next week. Hope this helps! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are running pg-boss (very successfully) on Heroku, using Heroku Postgres. Every now and again, Heroku performs scheduled maintenance on our database, which takes the DB offline for a short while.
We've set up our server to use an existing knex adapter, meaning that we have implemented
executeSql
to run the sql throughknex.raw
. We've also set up a global error handler to catch any emitted errors on the pgBoss instance, currently this logs out the error and then re-throws it.Here's how it currently looks:
The issue we're having is that when the database is unavailable, the
on('error'
listener is catching an error when a worker tries to pull down a job from the db. Since we have code to re-throw the error, this bubbles up and crashes the server. We'd like to gracefully handle this error, so that the server does not need to be restarted in this case.Here's an example of the error we get:
My first thought was to add some additional logic in the
on('error'
listener, to check if the error has the code ofECONNREFUSED
- if this is the case, we would log out the error, but not re-throw it, meaning that the server would not crash.My question - is this the recommended way to handle this sort of thing? My other thought was to add a
catch
to theknex.raw
call insideexecuteSql
, and return an artificially generated knex 'empty response' so that pg-boss thinks that no rows were returned. But I figured this is more error prone, and could have a knock-on effect elsewhere?Beta Was this translation helpful? Give feedback.
All reactions