Laravel interaction with external program - laravel

I would need to interact with an external program as follow:
On submit form the controller launches the external program
The program will send a code by SMS and wait for it for verification
The controller returns a new view with a form to ask for this code
On submit form the controller provides the code to the program
The main issue is this program is running in a blocking mode (it will wait for the code and return only after the verification), therefore I cannot execute it directly from the controller with symfony/process.
Instead I execute it in a queue job (is it the right thing to do?) which is launched on the first form submit, but I can't find out how to send to this running job the code obtained by the second form submit.
Is there a way to send information from a controller to an already running job?
Thank you.

I would change your workflow a little bit.
On submit form, the controller dispatches a job, that launches the external program
The program will send a code by SMS and wait for it for verification
When job with step 2 finishes (verification is done), it will fire off Notification, that will contain link to a new view with the form.
On submit form the controller provides the code to the program
Simple point is to not block the request, let the job handle it, as you pointed out in original question.
Form can be built anyway, implement echo server that will help you deliver message via websocket.
Is there a way to send information from a controller to an already running job?
No.

Related

Best practice to solve Livewire UI Not updating until after API call

I am using Laravel Livewire, I currently have a form that captures a user's address information, then it needs to submit that to a 3rd party API (it's for billing information).
The issue that I am facing is that the UI doesnt update / livewire doesnt call render until after the entire method has run - which looks on the frontend like the UI is frozen / system isnt doing anything as the API is slow and takes a few seconds (15 - 20) to give a response.
I want to be able to trigger a browser event to display an alert saying the request is processing / show an alert banner on the page that it is processing before making the API request, process the API request, then display the results.
Currently I have identified the following ways to make this happen:
make the updates on the frontend, fire off an event with the data needed. Laravel event listener handles the API call, and emits a result event that the livewire component listens for, then the livewire component updates the page with the results.
make the updates on the frontend, dispatch a job to run in a queue worker, emit an event that the livewire component listens for, update the page with the results.
emit an event from the livewire component to itself, the livewire component then listens for that event and processes the API request, then updates the frontend with the results.
emit an event from the livewire component to itself to update the UI with processing info, while it still runs the API process in the original method call, and then updates the UI once the API gets a response
My thoughts are, what would be best practice here? All the above solutions require a different amount of work to get running, and solution 1 and 2 looks like complete overkill for such a simple process.
Does this come down to preference? Or is there actually a best practice way to do this in livewire?
And additionally, is there another way / simpler way to do this that I havnt mentioned above?
Your feedback is appreciated.
I would probably create a job and then return a response to the user. Then instigate Livewire polling that can check for the job being complete. If the API takes 15-20 seconds then polling once per second should be fine.
You might want to store the state in the database so that the job and the livewire component can communicate with each other. If you don't need to keep the data, using the cache to communicate between job and component would be a good alternative.

Symfony3.4 - Send a Server-Sent Event when something happens

I'm developing a project with Symfony 3.4.
I would like to send a message to all the clients currently viewing a page when something happens. I evaluated both Server-Sent Events and Websockets, and I decided to go with the former, because the communication is unidirectional (only server to client).
For this purpose, I'm using this library: https://packagist.org/packages/tonyhhyip/sse
It seems to work, but I need to specifically send a message when something happens in the whole system. I tried with the Symfony event system (by creating a custom event), but events seem to be dispatched and captured only within the same session (i.e., the same logged user). In other words, if an action performed by a user triggers an event, it is not captured by other users and therefore a message is not sent to the browser via SSE.
Any suggestion?
Thank you

Dynamics Custom Action Process Session

I am working with a test action that when activated and called via javascript will fire an email message. I used an action because I wanted to pass in some values to be used in the process. In a traditional workflow I could see the history of each time the workflow was fired.
Is there a way to see all of the times my custom action fired?
Traditional workflow are Asynchronous. What you are seeing as Process Sessions are actually Async Execution logs. Those are not available/applicable for Sync jobs like Realtime workflows or Actions. Maybe you can keep the failure logs in Action.
Unfortunately you have to assume from the Emails that sent out is Action execution time.

Add Laravel Schedule in Controller Action

I have an web app that is supposed to scan any given site for metrics and send the report as an email. I fetch site url and email id from form and send it to controller action. Then in the action method, I want to run a system command in ubuntu to start the website scan and return the output to the method once done. I want to achieve the running of system command using laravel scheduler as using exec() command doesnt work as expected. If the command takes more time to execute then I get connection reset error. hence I wanted to schedule this task as cron job so that the execution can take its own time to complete and once completed, I can call another controller action to send the results to an email. Can someone help how to achieve this using laravel task scheduler.

Logic to use an API

I am using the MessageSave API to execute my .exe. My .exe takes the first argument from MessageSave API and does my work. When the user selects multiple messages and presses the button in the MessageSave software then the API sends multiple pings to my .exe but I want to execute my .exe when the last message is saved (meaning on the last ping). Can you please help me to write this coding logic?
About MessageSave: Message save is an AddIn for outlook on following url: http://www.techhit.com/messagesave/
API Link: http://www.techhit.com/messagesave/api.html
MessageSave does not provide any option for MultiMessages.
You will need to start on the first one, then the others can use one of the many forms of IPC (DDE, SendMessage with WM_COPYDATA, COM, etc) to pass the filename to the first copy.
From your description, there is no indication of first/last message so you can not get this notification.

Resources