我有这样的芹菜任务
from celery import shared_task
@shared_task
def send_to_sap(user_id):
user = User.objects.get(pk=user_id)
if settings.SYNCHRONIZATION:
response = requests.post(
settings.SOME_URL,
json={}
)
我想从视图中以异步模式执行它,我正试图像这个一样执行它
from tasks import send_to_sap
def send_to_sap(request, pk):
# some logic...
if serializer.is_valid():
serializer.save()
send_to_sap.apply_async(kwargs={'user_id': pk})
return Response(status=status.HTTP_200_OK)
send_to_sap.delay(pk)
我应该用delay()
打电话