问题描述
我正在开发django IPN插件,该插件可将IPN数据保存到模型中,然后调用post_save信号.
I'm developing a django IPN plugin that saves IPN data to a model and then calls a post_save signal.
我担心在这种用例(gunicorn,gevent等)下,信号可能会异步调用/完成.IPN通常会向ipn网址发送多个请求,而我需要能够按顺序处理这些请求.
I'm worried that under this use case (gunicorn, gevent, etc) that the signals may be called/completed asynchronously. The IPN often sends more than 1 request to the ipn url, and I need to be able to process those requests in order.
我应该为此使用队列吗?简单的python队列的工作会更好吗,还是我应该使用像kombu + celery之类的东西(有1个工人)?
推荐答案
不确定同步是否是您真正关心的问题.Django的信号始终在进程中执行:也就是说,它们将由执行其余请求的进程执行,然后返回响应.但是,如果您的服务器本身是异步的,则有可能一个请求将在第二个请求之后被完成,该请求随后会被接收,因此信号将以错误的顺序处理.
Not sure synchronicity is your real concern here. Django's signals are always executed in-process: that is, they will be executed by the process that did the rest of that request, before returning a response. However, if your server itself is asynchronous, there's a possibility that one request will finish processing after a second one that was received later, and therefore the signals will be processed in the wrong order.
当然,芹菜绝对是异步的,但如果可靠的订购对您来说是一个优先选择,那么它可能会是一个更好的选择.
Celery, of course, is definitely asynchronous, but might well be a better bet if reliable ordering is a priority for you.
这篇关于Django信号是否总是同步的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!