OurBG
OurBG

Reputation: 587

Laravel Job Batches - deadlock

I have a chain of two batches. One to prepare stuff and one to execute it. I had a lot of issues with it in the database, but I moved it to redis and it's perfect now.

However, the jobs are quite fast and apparently, there are times when two jobs are trying to update the same record in the job_batches table in my database.

Deadlock found when trying to get lock; try restarting transaction

And it points to /Bus/Batch.php

How can I solve that? Retrying kind of works, but in this case:

            Bus::batch($validatorBatch)->dispatch(),    
            Bus::batch($importerBatch)->dispatch(),
            ImportCleanupJob::dispatch($this->websiteImport),
        ]);

If one of the $validatorBatch fails due to this it goes through the whole thing first (even Importers) and then it goes back to finish the leftover validator, which is useless.

What is the right approach here, except dropping batches all together? I need them so I can do $batch->cancel() on the Importer job if any of the Validator ones fails.

Upvotes: 1

Views: 194

Answers (0)

Related Questions