[英]Inspecting Celery queues for tasks from Python
I have a Django+Celery application, where Celery is used to push (and pull) Django model instances to a third party SOAP service. 我有一个Django + Celery应用程序,其中Celery用于将Django模型实例推(拉)到第三方SOAP服务。
My Django models have dependencies between them and also a simple hash like this: 我的Django模型之间具有依赖关系,并且还具有以下简单哈希:
class MyModel(Models):
def get_dependencies(self):
# ...
return [...]
def __hash__(self):
return hash(self.__class__.__name__+str(self.pk))
This hash came handy in my own implementation which I had to drop due to stability issues. 在我自己的实现中,此哈希非常方便,由于稳定性问题,我不得不将其删除。 Celery is a much sounder ground.
芹菜的根基要好得多。
When I push an instance over to the SOAP service, I must make sure that its dependencies have been pushed. 将实例推送到SOAP服务时,必须确保已将其依赖项推送。 This is done by checking all related instances for a
pushed_ok
timestamp fields. 这是通过检查所有相关实例的
pushed_ok
时间戳字段来完成的。
The difficult part is when an instance a
which depends on list of instances deps
(all are instances of MyModel
subclasses) is being pushed. 困难的部分是当实例
a
取决于实例的列表deps
(均为实例MyModel
子类)被推动。 I cannot push a
unless all instances in deps
have been processed by Celery. 我不能推送
a
除非deps
所有实例都已被Celery处理。 In other words I need to serialize tasks so that the dependecies order is respected. 换句话说,我需要序列化任务,以便遵守依存关系顺序。
Celery is run like this: 芹菜是这样运行的:
celery -A server worker -P eventlet -c 100
How can I prevent one of the the eventlets (/process/thread) from running a
before its dependencies, if any, have finished being run by other eventlets? 我怎样才能防止在eventlets(/进程/线程)的一个运行
a
它的依赖之前,如果有的话,已完成被其他eventlets运行?
Thank you for your help. 谢谢您的帮助。
I went for a pragmatic solution of moving all dependency checking of a resource (which includes pushing out-of-sync dependencies to the soap server) inside the celery task. 我寻求了一个务实的解决方案,将所有资源的依赖检查(包括将不同步的依赖推送到soap服务器)移到了celery任务中。 Instead of trying to serialize tasks depending on the resources' dependencies.
而不是尝试根据资源的依赖性序列化任务。
The up side is that it keeps it simple and I could implement it rapidly. 有利的一面是它使它保持简单,我可以快速实现它。
The down side is that I'm locking a worker for a moment and potentially many synchronous SOAP operations instead of dispatching these operations accross workers. 不利的一面是,我暂时锁定了一个工作程序,并且可能会锁定许多同步SOAP操作,而不是在工作程序之间分派这些操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.