简体   繁体   English

Celery任务创建了一个新的模型对象,但是django signal不会将其拾取

[英]Celery task creates a new model object, but django signals doesn't pick it up

I've read around and see this has to do with concurrency, that celery can't edit the app variables because it's in a different thread from a python app. 我已经阅读了一下,发现这与并发有关,因为celery与python应用程序位于不同的线程中,因此它们无法编辑应用程序变量。 So instead I'm modifying the database by creating an object in the hope that django signal would've picked it up, but it's not. 因此,相反,我通过创建一个对象来修改数据库,希望django signal会选择它,但事实并非如此。 I'm doing this since I need to know if an update has occured in the back end so the SPA front end can fetch it automatically. 我这样做是因为我需要知道后端是否发生了更新,以便SPA前端可以自动获取它。 Any tips? 有小费吗?

Django signals only work in-process. Django信号仅在进程中工作。 So making a model change in celery will trigger the signal to occur in celery. 因此,在芹菜中进行模型更改会触发信号在芹菜中发生。 If you need to notify a single page app either (1) use a websocket or (2) pass the SPA the task_id so it can poll for when the task is complete and then take the necessary action. 如果您需要通知单个页面应用程序,则(1)使用websocket或(2)通过SPA将task_id传递给SPA,以便它可以在任务完成时进行轮询,然后采取必要的措施。

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

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