-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
balance udpate is not happening in Nova Action #455
Comments
Hello. Provide the code with which you change the balance. In general, you cannot change the balance parameter directly. |
public function handle(ActionFields $fields, Collection $models)
{
$title = 'Panel Transaction';
$meta = ['description' => $fields->description,'title' => $title];
/** @var User $model */
foreach ($models as $model) {
$model = $model->deposit($fields->amount, $meta);
$this->markAsFinished($model);
}
return Action::message('Site balance updated successfully!');
} |
when this code executed via laravel nova action , the transaction record is created in DB , but the balance is not updated but when I normally call "deposit" in other areas (like in controllers) it works I did some investigation and find out that BookkeeperService::sync is not getting called inside laravel nova action somehow I'm still investigating why |
I have the same issue. When I run the Version: ^7.3 /**
* Perform the action on the given models.
*
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param \Illuminate\Support\Collection $models
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models)
{
$model = $models->first();
$model->depositFloat($fields->amount, [
'label' => $fields->label,
'notes' => $fields->notes,
]);
return $model;
}
/**
* Handle chunk results.
*
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param array $results
* @return mixed
*/
public function handleResult(ActionFields $fields, $results)
{
$result = parent::handleResult($fields, $results);
if($result instanceof Model) {
$result->wallet->refreshBalance();
}
return $result;
} |
yeah it has something to do with the locking/blocking as a workaround a dispatch a job to do the deposit async @ysfkaya |
@sinamiandashti @ysfkaya Thank you. I'll try to debug this part this week. I have never tried to update the balance through nova. The admin panel was used only for displaying information. |
@sinamiandashti @ysfkaya At the moment, the solution is to put rollback in the first line. In the future, I will think about a solution out of the box, while there are no ideas. use Illuminate\Support\Facades\DB;
...
public function handle(ActionFields $fields, Collection $models)
{
DB::rollBack(0);
...
} |
If you can explain me how locking is working (or maybe in documentation) I could think about the solution |
It's not about blocking, but about the transaction that laravel nova hangs on the whole action. The package should now be able to correctly implement the saga (db + cache). We throw the balance into the cache and hang a lock for all operations. In case of an erroneous transaction, we should not update the data in the cache. You can read more about the state in a transaction here: #412 |
@rez1dent3 the same is happening if you run transactions in a migration, the balance in the wallet is only updated with |
@ibrunotome Yes, that's right. This is due to the framework transaction starting. If the package completely removes the fight against the race condition, then you can allow the use of framework transactions. Right now, I'm leaning towards adding a new exception that will tell the client about the transaction that was fired above. This will get rid of obvious errors. |
At the moment there is only one solution to these cases. If I come up with a different solution, I'll be sure to update the documentation. Now the performance of the package is in the foreground. Working with the internal state accelerated the package twice. |
Hi
I tried to deposit balance to a user wallet inside a Nova Action
but the balance of the wallet is not updating ... I'm not sure if it depends to Locking mecansim or queue of laravel nova actions
but the balance is not updating
any suggestion ?
The text was updated successfully, but these errors were encountered: