We give the user the ability to upload thousands of prospects from our web app (React.js).
Because it takes more than 1 minute for the Phoenix backend to finish sending all prospects to a third-party platform where we store the prospects, we show a progress bar to the user on the frontend side.
The user cancels the upload process anytime, or the user can do whatever activity they want while the upload process is in progress
How does the phoenix app handle this
It enqueues a worker module by using Exq.Enqueuer.enqueue. It creates a job process and in the perform function of that worker module, it sends the prospects to the third-party platform and send the status via WebSocket
What are we dealing with?
Once the user interacts with the cancel button on the frontend side, the phoenix app should inform the corresponding worker module that it should stop sending prospects and rollback the successfully sent ones. Finally, the job process (the worker module) should be destroyed
What’s the problem?
We could not figure out how to send a message from the phoenix request handler to the corresponding job process.
When enqueueing a worker module, it returns a Job ID. Not sure how we can map the Job ID to a PID.