0

Using django-celery, I'm trying to create some sub tasks from within a main task but am getting this error: received unregistered task of type 'smallTask'.

Any idea what's wrong please? And if this is the right way to create sub tasks in this way?

Thanks,

@task
def mainTask():
    count = 0
    logger = mainTask.get_logger()
    logger.info('LOGGER: in main task')

    while count < 10:
        subtask('smallTask', args=(count), countdown=0).apply_async()
        count += 1

@task
def smallTask():
    logger = smallTask.get_logger()
    logger.info('LOGGER: in main task')
4

1 回答 1

2

不确定这是否是最好的方法,但是在另一个问题的 SO 上提供了一些额外的帮助,我现在可以使用它。

@task
def mainTask():
    count = 0
    logger = mainTask.get_logger()
    logger.info('LOGGER: in main task')
    obj = {'foo':'bar'}
    while count < 10:
        subtask('smallTask', args=(obj,)).apply_async()
        count += 1

@task(name='smallTask')
def smallTask():
    logger = smallTask.get_logger()
    logger.info('LOGGER: in sub task')
于 2013-07-11T14:38:07.827 回答