timgit / pg-boss

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

Decouple creation of tables with monitoring/archiving #148

Closed leventov closed 4 years ago

leventov commented 4 years ago

Currently, start() is responsible for both creation of pg-boss's tables in the database, and monitoring/archiving jobs. When starting multiple actors using docker-compose (alongside a database), we cannot be sure which actor will hit the database first. So, I think it makes sense to make connect() to also create the tables if they are absent yet. Perhaps, via opt-in boolean parameter connect(createTables).

timgit commented 4 years ago

I’ve made significant changes to bootstrapping in a beta release of v4. Would you be willing to give this version a try in your environment? It was created for a similar use case in docker we were running into in aws.

leventov commented 4 years ago

I use v4 beta now. Is this the case in the new version that connect() creates all the necessary tables if they don't exist yet as well as start()?

timgit commented 4 years ago

The behavior of connect() hasn’t changed, but you should use start() instead, as it will block with a promise how you’re needing.

leventov commented 4 years ago

I think the issue was that if start() is called from both actors out of necessity (because calling connect() from either one may result in "tables for pg-boss don't exist..." error), we needlessly do monitoring/archiving from both actors.

timgit commented 4 years ago

Only one instance using start() will issue maintenance commands, so this is fine. I've documented how this works in the changelog