I have a web app created in Laravel that takes credit card payments.
Every day a scheduled command that I created runs to take "today's" payments (basically it submits one http request for each pending payment to the payment gateway).
Now I need to allow to trigger this payment submission process via a button in a dashboard.
The command takes a random long time to process (depending on the number of payments to process), so call it from the controller I think is not an option.
I'm thinking of just refactor it: move all the command code to a "middleman" class so I could call this class on both the command and the controller.
PaymentsSubmissionHelper::submit()
PaymentsSubmissionCommand: PaymentsSubmissionHelper::submit()
PaymentsSubmissionController: PaymentsSubmissionHelper::submit()
However, the command shows a progress bar and the estimated time to process and I will need to show a progress bar in the html interface as well. In the web interface I will need to make ajax requests to the server to get the current progress but in the command this progress is tracked in a completely different way using:
$bar = $this->output->createProgressBar($totalPayments);
$bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %message%');
and for each processed payment:
$bar->advance();
How can I create keep track of the progress on both the command and the controller?
Any help will be appreciated.
Thanks in advance!