@@ -23,6 +23,8 @@ def internal_webhook_endpoint(request):
2323 content = json .loads (request .body ),
2424 extra = {},
2525 )
26+ # Schedule a task for the worker to process the webhook outside of
27+ # request/response cycle.
2628 process_webhook .enqueue (str (wh .uuid ))
2729
2830 return JsonResponse ({"status" : "created" , "guid" : wh .uuid })
@@ -45,22 +47,24 @@ def verify_internal_webhook(request):
4547@csrf_exempt
4648def github_webhook_endpoint (request ):
4749 if request .method == "POST" :
48- github_headers = {
49- k : v for k , v in request .headers .items () if k .startswith ("X-Github" )
50- }
51-
5250 try :
5351 signature = verify_github_signature (request )
5452 except ValueError as e :
5553 return HttpResponseForbidden (e )
5654
55+ github_headers = {
56+ k : v for k , v in request .headers .items () if k .startswith ("X-Github" )
57+ }
58+
5759 wh = Webhook .objects .create (
5860 source = "github" ,
5961 meta = github_headers ,
6062 signature = signature ,
6163 content = json .loads (request .body ),
6264 extra = {},
6365 )
66+ # Schedule a task for the worker to process the webhook outside of
67+ # request/response cycle.
6468 process_webhook .enqueue (str (wh .uuid ))
6569 return JsonResponse ({"status" : "created" , "guid" : wh .uuid })
6670
@@ -92,26 +96,27 @@ def verify_github_signature(request) -> str:
9296@csrf_exempt
9397def zammad_webhook_endpoint (request ):
9498 if request .method == "POST" :
95- zammad_headers = {
96- k : v for k , v in request .headers .items () if k .startswith ("X-Zammad" )
97- }
98-
9999 try :
100100 signature = verify_zammad_signature (request )
101101 except ValueError as e :
102102 return HttpResponseForbidden (e )
103103
104+ zammad_headers = {
105+ k : v for k , v in request .headers .items () if k .startswith ("X-Zammad" )
106+ }
107+
104108 wh = Webhook .objects .create (
105109 source = "zammad" ,
106110 meta = zammad_headers ,
107111 signature = signature ,
108112 content = json .loads (request .body ),
109113 extra = {},
110114 )
115+ # Schedule a task for the worker to process the webhook outside of
116+ # request/response cycle.
111117 process_webhook .enqueue (str (wh .uuid ))
112118 return JsonResponse ({"status" : "created" , "guid" : wh .uuid })
113119
114-
115120 return HttpResponseNotAllowed ("Only POST" )
116121
117122
0 commit comments