我在我的tasks.py
文件中注册了一个 Celery 任务。当有人发布到 /run/pk 时,我使用给定的参数运行任务。此任务还执行其他任务(普通 Python 函数),并且我想在子任务完成其工作时更新我的页面(在 /run/pk 返回的 HttpResponse)。
这是我的任务:
from celery.decorators import task
@task
def run(project, branch=None):
if branch is None:
branch = project.branch
print 'Creating the virtualenv'
create_virtualenv(project, branch)
print 'Virtualenv created' ##### Here I want to send a signal or something to update my page
runner = runner(project, branch)
print 'Using {0}'.format(runner)
try:
result, output = runner.run()
except Exception as e:
print 'Error: {0}'.format(e)
return False
print 'Finished'
run = Run(project=project, branch=branch,
output=output, **result._asdict())
run.save()
return True