You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing an issue where the wallet balance is not updated correctly inside a job when the job is run multiple times. Here are the steps to reproduce the issue:
1-Job Dispatch:
I dispatch a job to process a group of users:
2-Job Logic:
Inside the job, I loop through a group of users and perform the following operations for each user:
Get the user's wallet:
$wallet = $user->getWallet('seller');
Check the wallet balance. If the balance is less than or equal to zero, return an error message and skip the user
if ($wallet->balance <= 0) {
return 'inherited wallet balance less/equal zero inherited_id';
continue;
}
Insert a withdrawal record into the transactions table and refresh the wallet:
DB::table('transactions')->insertGetId($data);
$wallet->refreshBalance();
3-Expected Behavior:
After the first job run, the wallet balance should be updated to 0.
When the job runs again for the same user, the $wallet->balance should reflect the updated balance (0).
4-Actual Behavior:
When the job runs for the second time, $wallet->balance still returns the balance before the withdrawal operation.
The balance is only updated correctly after restarting the worker.
The database is updated correctly (the balance is 0 in the database), but the job does not reflect this change.
5-Additional Observations:
The balance is correct when checked in the user profile after the first job run.
The issue only occurs inside the job when it is run multiple times.
Could you please help me understand what the problem might be? Is this a known issue, or am I missing something in my implementation? If there’s anything unclear in my description, please let me know, and I’ll be happy to provide more details or clarify furthe
The text was updated successfully, but these errors were encountered:
Hello. Direct data insertion is not allowed. You need to work with wallet methods and put locks, otherwise you will get a race condition, which is what you are experiencing.
Your problem is exactly in this code:
if ($wallet->balance <= 0) {
return'inherited wallet balance less/equal zero inherited_id';
}
DB::table('transactions')->insertGetId($data);
$wallet->refreshBalance();
Firstly, you do not block work with the wallet during the verification, which means that the user can continue working with the wallet after checking your condition.
I am experiencing an issue where the wallet balance is not updated correctly inside a job when the job is run multiple times. Here are the steps to reproduce the issue:
1-Job Dispatch:
I dispatch a job to process a group of users:
dispatch(new TransferInheritanceJob())->onQueue('inheritance');
2-Job Logic:
Inside the job, I loop through a group of users and perform the following operations for each user:
Get the user's wallet:
$wallet = $user->getWallet('seller');
Check the wallet balance. If the balance is less than or equal to zero, return an error message and skip the user
if ($wallet->balance <= 0) {
return 'inherited wallet balance less/equal zero inherited_id';
continue;
}
Insert a withdrawal record into the transactions table and refresh the wallet:
DB::table('transactions')->insertGetId($data);
$wallet->refreshBalance();
3-Expected Behavior:
After the first job run, the wallet balance should be updated to 0.
When the job runs again for the same user, the $wallet->balance should reflect the updated balance (0).
4-Actual Behavior:
When the job runs for the second time, $wallet->balance still returns the balance before the withdrawal operation.
The balance is only updated correctly after restarting the worker.
The database is updated correctly (the balance is 0 in the database), but the job does not reflect this change.
5-Additional Observations:
The balance is correct when checked in the user profile after the first job run.
The issue only occurs inside the job when it is run multiple times.
6-Environment:
PHP version: 8.1.0
Database: MySQL
Laravel Wallet version: 10.1.0
Cache lock: Redis
Cache wallets: Redis
Could you please help me understand what the problem might be? Is this a known issue, or am I missing something in my implementation? If there’s anything unclear in my description, please let me know, and I’ll be happy to provide more details or clarify furthe
The text was updated successfully, but these errors were encountered: