-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to run jobs concurrently ? #542
Comments
You will need to handle concurrency yourself in your handler. A simple example would be something like the following. async function handler(job) {
// todo
}
await boss.work(queue, { batchSize: 2 }, (jobs) => Promise.allSettled(jobs.map(handler))) There are other packages, such as p-map, that add more options, such as concurrency control. |
Hi @timgit, could you further explain how you would implement concurrency with pg-boss? This approach using |
You're right, each worker will wait until the entire batch is processed before pulling more jobs down. Another option is to create multiple workers, as in the following example where 3 workers are created. Workers will not block each other, so you could use something like this if needed. await boss.work(queue, { batchSize: 2 }, (jobs) => Promise.allSettled(jobs.map(handler)))
await boss.work(queue, { batchSize: 2 }, (jobs) => Promise.allSettled(jobs.map(handler)))
await boss.work(queue, { batchSize: 2 }, (jobs) => Promise.allSettled(jobs.map(handler))) |
Hi.
Second job becomes active after first job completes. batchSize works only when i send jobs immediately one after another.
If the job completes within 5min and we don't run them concurrently, 10'th job will be completed within 50mins.
In previous version (pg-boss v9) we can do it using {teamSize: 2, teamConcurrency: 2, teamRefill: true} (without teamRefill doesn't work concurrently, do you know why?)
The text was updated successfully, but these errors were encountered: