timgit / pg-boss

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

Request: export Contractor class (or just the `start` method) #243

Closed nicoburns closed 3 years ago

nicoburns commented 3 years ago

Hi there. I'm currently working on integrating pg-boss into our backend and I have a request.

I want to make use of pg-boss's automatic tracking of schema version, and it's ability to compute which migrations should be run. However, I don't want pg-boss to run these migrations every time it starts up because this could cause a single microservice with the upgraded version to inadvertently upgrade the schema for the pg-boss tables causing clients still on an older version to stop working.

This what I want to do is have a method in PgBoss that I can call with my database credentials at a time of my choosing that runs the migrations. Contractor.start() seems to be the method to do this. It seems that I can get at this method by calling PgBoss.start(), which should work fine. But this also does a whole bunch of other stuff which I don't really need at "migration time" and seems like it could potentially cause issues (even if this is unlikely).

I am therefore wondering if either:

Thanks for the generally great seeming library. Nico

timgit commented 3 years ago

There are a couple of constructor options you can pass which might accomplish what you're looking for.

noSupervisor will bypass maintenance and noScheduling will bypass cron monitoring

timgit commented 3 years ago

I actually have this same code set up in up my app for similar purposes of migration-only bootstrapping.

async function init(options) {
    const b = new PgBoss({ ...options, noSupervisor: true, noScheduling: true })
    await b.start()
    await b.stop()
}
nicoburns commented 3 years ago

Ah yes, thanks for your response. This is working fine for my use case :)