|
1 | 1 | [](https://travis-ci.org/zapier/django-rest-hooks)
|
2 | 2 | [](https://pypi.python.org/pypi/django-rest-hooks)
|
3 | 3 | [](https://pypi.python.org/pypi/django-rest-hooks)
|
4 |
| -## What are Django REST Hooks? |
| 4 | +## What are Django REST Hooks? |
5 | 5 |
|
6 | 6 |
|
7 | 7 | REST Hooks are fancier versions of webhooks. Traditional webhooks are usually
|
@@ -361,20 +361,31 @@ import requests
|
361 | 361 |
|
362 | 362 |
|
363 | 363 | class DeliverHook(Task):
|
364 |
| - def run(self, target, payload, instance=None, hook=None, **kwargs): |
| 364 | + def run(self, target, payload, instance_id=None, hook_id=None, **kwargs): |
365 | 365 | """
|
366 | 366 | target: the url to receive the payload.
|
367 | 367 | payload: a python primitive data structure
|
368 |
| - instance: a possibly null "trigger" instance |
369 |
| - hook: the defining Hook object |
| 368 | + instance_id: a possibly None "trigger" instance ID |
| 369 | + hook_id: the ID of defining Hook object |
370 | 370 | """
|
371 | 371 | requests.post(
|
372 | 372 | url=target,
|
373 | 373 | data=json.dumps(payload),
|
374 | 374 | headers={'Content-Type': 'application/json'}
|
375 | 375 | )
|
376 | 376 |
|
377 |
| -deliver_hook_wrapper = DeliverHook.delay |
| 377 | + |
| 378 | +def deliver_hook_wrapper(target, payload, instance, hook): |
| 379 | + # instance is None if using custom event, not built-in |
| 380 | + if instance is not None: |
| 381 | + instance_id = instance.id |
| 382 | + else: |
| 383 | + instance_id = None |
| 384 | + # pass ID's not objects because using pickle for objects is a bad thing |
| 385 | + kwargs = dict(target=target, payload=payload, |
| 386 | + instance_id=instance_id, hook_id=hook.id) |
| 387 | + DeliverHook.apply_async(kwargs=kwargs) |
| 388 | + |
378 | 389 | ```
|
379 | 390 |
|
380 | 391 | We also don't handle retries or cleanup. Generally, if you get a `410` or
|
|
0 commit comments