Defining Hooks - durian.hook

class durian.hook.Hook(name=None, task_cls=None, timeout=None, async=None, retry=None, max_retries=None, fail_silently=False, config_form=None, provides_args=None, match_forms=None, **kwargs)

A Web Hook Event.

Parameters:
name

The name of the hook.

If not provided this will be automatically generated using the class module and name, if you want to use this feature you can’t use relative imports.

provides_args
The list of arguments the event provides. This is the standard list of arguments you are going to pass on to send(), used to generate the filter events form (match_forms).
config_form
A Django form to save configuration for listeners attaching to this form. The default form is durian.forms.HookConfigForm, which has the URL field.
timeout
The timeout in seconds before we give up trying to dispatch the event to a listener URL.
async
If True, signals are dispatched to celery workers via a mesage. Otherwise dispatch happens locally (not a good idea in production).
retry
Retry the task if it fails.
max_retries
Maximum number of retries before we give up.
fail_silently
Fail silently if the dispatch gives an HTTP error.
task_cls
The celery.task.base.Task class to use for dispatching the event.
match_forms
A list of forms to create an event filter. This is automatically generated based on the provides_args attribute.
add_listener(url, match={}, **config)

Add listener for this signal.

Parameters:
  • url – The url the listener is listening on.
  • match – The even filter match dict.
  • **config – Hook specific listener configuration.
add_listener_by_form(form, match=None)

Add listener with an instantiated config_form.

Parameters:
  • form – An instance of config_form.
  • match – Optional event filter match dict.
apply_match_forms(data)
With data recieved by request, convert to a list of match tuples.
event_filter(sender, payload, match)

How we filter events.

Parameters:
  • sender – The sender of the signal.
  • payload – The signal data.
  • match – The match dictionary, or None.
get_applier(async=None)
Get the current apply method. Asynchronous or synchronous.
get_listeners(sender, payload)
Get a list of all the listeners who wants this signal.
get_match_forms(**kwargs)

Initialize the match forms with data recived by a request.

Returns:A list of instantiated match forms.
listener(form)
Create a new listener.
prepare_payload(sender, payload)

Prepare the payload for dispatching.

You can add any additional formatting of the payload here.

send(sender, **payload)

Send signal and dispatch to all listeners.

Parameters:
  • sender – The sender of the signal. Either a specific object or None.
  • payload – The data to pass on to listeners. Usually the keys described in provides_args and any additional keys you’d want to provide.
task_keywords
The keyword arguments sent to the celery task.
class durian.hook.ModelHook(model=None, **kwargs)
>>> from django.db import signals
>>> from django.contrib.auth.models import User
>>> hook = ModelHook(User, signals.post_save,
...                  name="user-post-save",
...                  provides_args=["username", "is_admin"])
>>> joe = User.objects.get(username="joe")
>>> joe.is_admin = True
>>> joe.save()
class durian.hook.SignalHook(signal=None, **kwargs)
Hook attached to a Django signal.

Previous topic

Module API Reference

Next topic

Celery Tasks - durian.tasks

This Page