芹菜任务运行更多的任务 [英] Celery task that runs more tasks

查看:96
本文介绍了芹菜任务运行更多的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用芹菜来启动主要的任务,踢了一些次要任务。我有两个任务已经写完了。



有没有办法轻松做到这一点?芹菜是否允许从任务中运行任务?



我的例子:

  @task 
def compute(users = None):
如果用户为None:
users = User.objects.all()

tasks = []
用户用户:
tasks.append(compute_for_user.subtask((user.id,)))

job = TaskSet(tasks)
job .apply_async()#引发IOError:Socket关闭

@task
def compute_for_user(user_id):
#do某些东西

计算从celerybeat调用,但在尝试运行<$ c $时会导致IOError C> apply_async 。任何想法?

解决方案

回答您的开场白问题:从版本2.0开始,Celery提供了一种简单的方法来从其他任务启动任务。你所谓的辅助任务就是它所谓的子任务。请参阅任务集,子任务和回调的文档,其中@ Paperino可以链接到。



对于版本3.0,Celery更改为使用,以及其他类型的行为。



您的代码显示您已经熟悉此界面。你的实际问题似乎是,当我尝试运行我的子任务集时,为什么我得到一个'Socket Closed' IOError ?我不认为有人可以回答,因为你没有提供足够的关于你的程序的信息。您的摘录无法按原样运行,所以我们无法检查您自己遇到的问题。请张贴与 IOError 一起提供的堆栈跟踪,任何运气,可以帮助您与您的螃蟹的人将会来。


I am using celerybeat to kick off a primary task that kicks of a number of secondary tasks. I have both tasks written already.

Is there a way to easily do this? Does Celery allow for tasks to be run from within tasks?

My example:

@task
def compute(users=None):
    if users is None:
        users = User.objects.all()

    tasks = []
    for user in users:
        tasks.append(compute_for_user.subtask((user.id,)))

    job = TaskSet(tasks)
    job.apply_async() # raises a IOError: Socket closed

@task
def compute_for_user(user_id):
    #do some stuff

compute gets called from celerybeat, but causes an IOError when it tries to run apply_async. Any ideas?

解决方案

To answer your opening questions: As of version 2.0, Celery provides an easy way to start tasks from other tasks. What you are calling "secondary tasks" are what it calls "subtasks". See the documentation for Sets of tasks, Subtasks and Callbacks, which @Paperino was kind enough to link to.

For version 3.0, Celery changed to using groups for this, and other, types of behavior.

Your code shows that you are already familiar with this interface. Your actual question seems to be, "Why am I getting a 'Socket Closed' IOError when I try to run my set of subtasks?" I don't think anyone can answer that, because you have not provided enough information about your program. Your excerpt cannot be run as-is, so we cannot examine the problem you're having for ourselves. Please post the stacktrace provided with the IOError, and with any luck, someone that can help you with your crasher will come along.

这篇关于芹菜任务运行更多的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆