Have you tried using the after_commit flag described here?
https://laravel.com/docs/10.x/queues#jobs-and-database-transactions
The case is that I want to insert data into 2 tables using a transaction. As far as I know, transactions in the database ensure data consistency. However, in my case, the data in table 1 didn't go in, but the data in table 2 did. I checked the query logs those 2 query is there. But when I get the Table1 data inside the job, the data is not exists and so does in the database, and there was no 'delete from' query in the logs. So, I assume this might be related to the table during the transaction that could possibly resulting in partial insertion. Are there any other factors that could cause this case?
Also, this happen occasionally, not like everytime. But lately this happened quite frequent.
Here is my controller code:
try {
DB::beginTransaction();
Table1::create(...);
Table2::create(...);
DB::commit();
dispatch(...);
} catch($th) {
DB::rollBack();
}
And here is the queue code:
public function handle(){
$data = Table1::find($this->id_table1);
if ($data === null) {
// data Table1 doesn't exist
// data Table2 exists
}
}
Please or to participate in this conversation.