Reputation: 11
I am using laravel 8 for my application and every is working fine except sometimes my queue jobs are running twice which is causing database ledger balance to update twice .
I found out this issue before also but neglected thinking my code might be wrong but yesterday also I encountered same issues. This issues is not happening with all jobs but in very few like 1-2 jobs in 100 jobs. I am using database driver for managing jobs.
Here is my code implementation
I using following in my job file
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $retryAfter = 85;
public $timeout = 80;
public $tries = 3;
my code is not calling jobs twice I have checked it also I am using supervisor for managing queues and I have attached supervisor config.
I am using below code to dispatch job
UpdateDailyLedgerReport::dispatch($this->ledger_id, $this->name, $type, $date, $amount);
I have checked my code multiple times but there is no trace of calling jobs twice and the things is sometime while update two ledger balances i.e model with equal amount one model is getting update with correct amount but second model balance is updated twice .
Same issue I have seen with my another job .
Thanks.
Previous my jobs timeout was only 30 sec but I have increased it and still the issues is there.
Just now I have checked and found out following is causing isseus:
SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction (SQL: delete from jobs where id = 10892) {"exception":"[object] (Illuminate\Database\QueryException(code: 40001): SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction (SQL: delete from jobs where id = 10892) at /var/www/vhosts/poshbooks.in/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712)
can anyone help me to fix it
Upvotes: 1
Views: 939
Reputation:
The jobs must be idempotent. Meaning if they execute more than once they should not break your logic. Increment the ledgers without jobs. On deploys it could happen if the sigterm signal is not handled properly.
Upvotes: 0