<s> import requests <EOL> import json <EOL> from celery . task import Task <EOL> from django . core . serializers . json import DjangoJSONEncoder <EOL> from rest_hooks . models import Hook <EOL> class DeliverHook ( Task ) : <EOL> def run ( self , target , payload , instance = None , hook_id = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = requests . post ( <EOL> url = target , <EOL> data = json . dumps ( payload , cls = DjangoJSONEncoder ) , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } <EOL> ) <EOL> if response . status_code == <NUM_LIT> and hook_id : <EOL> hook = Hook . object . get ( id = hook_id ) <EOL> hook . delete ( ) <EOL> def deliver_hook_wrapper ( target , payload , instance = None , hook = None , ** kwargs ) : <EOL> if hook : <EOL> kwargs [ '<STR_LIT>' ] = hook . id <EOL> return DeliverHook . delay ( target , payload , ** kwargs ) </s>
