Friday 22 November 2019

How would you go about this: 1) User interacts with front-end. 2) Back-end performs some tasks accordingly. 3) Notify user when response is ready.

I'm working on a web application where users can perform a "search" by filling out and submitting a form. The back-end will then use Puppeteer to pull some data from another website*. During testing, I've found that this fetching of data typically takes between 5 and 10 seconds.Now, when the data is ready I would like to notify the client somehow. I've been considering Socket.io but I'm still not 100% sure that's the best tool for the job.As things are, submitting a search will:Redirect the user to a page called "My searches" that basically gives them their search history (searches and results) and allows them to interact with it.Store the search in a database (MongoDB).Run Puppeteer to fetch "search results".Store the search results in a database, with a column "searchId" referencing the search.Now, I'd like to expand this so that after step 4, the user is notified. I have a few relevant scenarios in mind here:The user is still logged in and on the "My searches" page.The user is still logged in but navigated away from "My searches".The user has logged out.Regardless of the above - the user is also logged in on another device.I'd like to handle all of these scenarios. For scenario #1 it'd be nice if I was also able to update the UI directly (but in some way that makes it obvious that it happened).For the other scenarios, I'm thinking maybe I should implement navbar notifications? For that I guess I should probably store notifications in a database as well.Nonetheless - I still don't have any better ideas than Socket.io. And even then, I've never worked with Socket.io so I'm not 100% sure how to securely and relibably tie socket IDs to individual users. (Multiple socket IDs in the case of simultaneous sessions on multiple devices.)Is Socket.io the way to go here? Any other ideas?*I'm using Puppeteer rather than web requests because the website requires a login and some kind of MFA that I've been able to automate only with Puppeteer so far.

Submitted November 22, 2019 at 05:51PM by BillGoats

No comments:

Post a Comment