Clarification for afterCommit in Laravel Queues

Viewed 763

I am dispatching jobs that perform time consuming tasks when I receive a request. e.g. Send the user a welcome email when they sign up on the site

The request however dispatches the email job within a transaction and a race condition occurs. The job might execute before the transaction is committed and hence fail with a user not found error. I read about using afterCommit when dispatching the job but the doc says "Laravel will wait until all open database transactions have been committed before actually dispatching the job"

Does this mean if there are multiple transactions open from different requests, Laravel will wait for all of them to close or just the transactions related to the current request that might generated the job?

1 Answers

As far as I know laravel will wait for that particular transaction in which job is created, if that transaction is child transaction then laravel will wait until parent transaction to commit. Hope this answer helped you.

Related