mercredi 17 juillet 2019

Best practice to create "flag" for multiprocess project with db as bridge between processes?

I have two processes: 1) scrapper - take info from another website, do the needfull calculations and put results in db 2) web app (Flask) take data from db and draw plot with the help of matpotlib. The two processes do not communicate, but they use one db.

Problem: All works fine now, but to draw plots and save them to folder of web app project is time consuming operation, it takes about 5 seconds to display the page with plots. Pictures are created every time the webpage is requested, since data can be added to db in random moment and user should get plot with all information.

How I see the solution: To create table in db with only one line and only two colums: id = 1 and boolean field in db. Let's call boolean column IS_UPDATED. When the scrapper process put some new data to db, we change IS_UPDATED to True. When the second process web app ask the data from db, it changes IS_UPDATED to False. Hereby the pictures are recreted only when new data was provided to db by the scrapper process, otherwise we use the old pictures.

Is my solution is fine? Please share any other ways to do the same.

Aucun commentaire:

Enregistrer un commentaire