简体   繁体   English

Flask - 无尽的后台进程

[英]Flask - endless background process

I'm working on flask project to collect measurement data from IOT sensors in database.我正在研究 flask 项目,以从数据库中的物联网传感器收集测量数据。 Application have endopoints for sensors and for frontend.应用程序具有传感器和前端的端点。 Currently I have to add endless background process, that check some data in database like communication timeouts, exceeding the alarm levels etc. and send sms/emails alerts.目前我必须添加无尽的后台进程,检查数据库中的一些数据,如通信超时、超过警报级别等,并发送短信/电子邮件警报。 What is the proper way to do that.这样做的正确方法是什么。 Thread is tempting for me, but I wonder how to avoid multiple threads when I run multiple workers with gunicorn.线程对我来说很诱人,但我想知道当我用 gunicorn 运行多个 worker 时如何避免多个线程。 Of course i want to use all my DB models and flask-sqlalchemy.当然我想使用我所有的数据库模型和flask-sqlalchemy。 I read Miguel Grinberg blog about Background Jobs but I have doubts about it is the proper way to resolve my problem.我阅读了关于后台作业的 Miguel Grinberg 博客,但我怀疑它是否是解决我的问题的正确方法。

An event based approach is far better than a polling approach (endless répétition of the same task to check for some condition).基于事件的方法比轮询方法好得多(对同一任务进行无休止的重复以检查某些条件)。 It would preferable to check data before storing them in the data base or executing a task to check data upon an update of the data base.最好在将数据存储在数据库中之前检查数据,或者在更新数据库时执行检查数据的任务。 As for timeout an error should occur and should be related to an exception that would run a fallback task.至于超时,应该会发生错误,并且应该与运行回退任务的异常有关。 To summarize use an event based pattern to check rather a continuous backgroud task.总而言之,使用基于事件的模式来检查一个连续的背景任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM