我试图设置一个简单的webhook,其中传入的请求由芹菜工人处理。
这是view.py
中的钩子:
@method_decorator(csrf_exempt, name='dispatch')
class SendGridCallbackView(View):
def post(self, request, *args, **kwargs):
print('TEST')
req_dict = {'request': request.body}
sendgrid_email_tracking.apply_async(kwargs=req_dict)
return HttpResponse(status=200)
tasks.py
中定义的任务:
@shared_task(base=WorkerBase, name='mailer.sendgrid-tracking-mail')
def sendgrid_email_tracking(**kwargs):
print('GOTCHA')
从sendgrid发送测试邮件时,会打印TEST
输出,但芹菜工作者会返回错误
TypeError: sendgrid_email_tracking() got an unexpected keyword argument 'request'
当我添加其他参数*args
时,错误消失,但在被调用的方法中,*args
和**kwargs
都为空
@shared_task(base=WorkerBase, name='mailer.sendgrid-tracking-mail')
def sendgrid_email_tracking(*args, **kwargs):
print(args) # prints -> ()
print(kwargs) # prints -> {}