在芹菜中使用共享_task时,如何在任务执行之前运行代码
我要求我所有的芹菜任务都必须用特定的关键字参数调用。我想在执行任务之前检查并使用关键字的值。 例如,假设我有以下内容:
@shared_task
def my_task(*args, **kwargs):
foo = kwargs.get('bar') # -> I don't want to copy this to all my tasks
# Do stuff here
如何创建一个名为my_special_shared_task
的新装饰器,以便以下内容等同于上述:
@my_special_shared_task
def my_task(*args, **kwargs):
# Do stuff here
I have a requirement that all my Celery tasks must be called with a specific keyword argument. I want to check and use the value of the keyword before my task is executed.
For instance, suppose I have the following:
@shared_task
def my_task(*args, **kwargs):
foo = kwargs.get('bar') # -> I don't want to copy this to all my tasks
# Do stuff here
How can I create a new decorator called my_special_shared_task
so that the below is equivalent to the above:
@my_special_shared_task
def my_task(*args, **kwargs):
# Do stuff here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那任务继承呢?
类似:
在这里是文档。
What about task inheritance?
something like:
here is the documentation.