2

如何协调 Flask 和其他不间断运行的 Background 程序?

 2 years ago
source link: https://www.v2ex.com/t/831723
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Web Dev

如何协调 Flask 和其他不间断运行的 Background 程序?

  leimao · 2 天前 · 1148 次点击

各位好,小白(并不懂 Full Stack 和其他网络相关技术)在用 Flask 写一个很小的 web App 的时候有一些架构和技术上的疑问,请求帮助和解答。

这个 Web App 很简单,是这样的。

  1. 它有一个数据库,这个数据库会被一个程序 A 24 小时不间断的更新。
  2. 程序 B 24 小时不间断的每隔一定时间对这个总是被更新的数据库进行 query ,然后生成一个 summary 。这个 summary 最好是在内存上的某个数据结构,方便其他程序读取。
  3. 程序 C ,也就是 Flask Web Server ,会根据用户的请求,返回 summary 中的一部分给用户。

这三个程序 A ,B 和 C ,每一个用 Python 看起来都不难写。但是怎么把这三个东西有机结合起来,并且(用 gunicorn ?)部署,我有些困惑。原本觉得这不就是三个 thread 或者三个 process 么,放到 flask Python app 里,flask run 的时候这三个 thread 同时 asyn 的运行。但是看到 flask 本身在(用 gunicorn ?)部署的时候似乎不是很支持自定义的 async 的东西,似乎也不支持另外单独开一个 thread ,始终运行一个任务,就不是很清楚怎么把这三个东西揉在一起了。

请有经验的同学给一些建议,谢谢。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK