我使用django-rest-framework和芹菜 这是我的views.py
# GET /server/test/<para>/
class Testcelery(APIView):
def test(self):
print(celery_test())
def get(self, request, para, format=None):
print('test')
self.test()
# result = add.delay(4, 4)
# print(result.id)
result = OrderedDict()
result['result'] = 'taskid'
result['code'] = status.HTTP_200_OK
result['message'] = 'success'
return Response(result, status=status.HTTP_200_OK)
这是一个简单的芹菜任务
@shared_task()
def celery_test():
print('celerytest')
return True
我调试了django it can goes to the test method
但该计划停留在local.py中调用的下一步 where the error happens
调试在那里停止,并显示如下 debug result
答案 0 :(得分:0)
有几个问题:
任务应该与whatever.delay()
http://docs.celeryproject.org/en/latest/userguide/calling.html#basics
我不打电话给Testsomething
课,除非它是考试类
确保工作正在运行并且已正确初始化。别忘了检查经纪人是否正常运行。
调试时,请考虑芹菜工人是一个不同的过程。您的调试器可能仅附加到运行manage.py的进程。如果您将IDE作为命令运行,则可能更容易调试。