Stay informed of it
Project description
Django Whisperer
Whisperer informs subscribed users via an URL when a specific event occurs.
Installation
Installation using pip:
pip install dj-whisperer
whisperer
package has to be added to INSTALLED_APPS
and migrate
command has to be run.
INSTALLED_APPS = (
# other apps here...
'whisperer',
)
Sample Scenario
Let's give an example using Package
model. When an event occurs related to a package, subscribed users are gonna be informed. To do so, firstly which events to subscribe must be determined. In order to learn when a package created:
from django.db.models.signals import post_save
from whisperer.events import WhispererEvent, registry
from whisperer.tasks import deliver_event
class PackageCreateEvent(WhispererEvent):
serializer_class = PackageSerializer
event_type = 'package-created'
registry.register(PackageCreateEvent)
def signal_receiver(instance, created=False, **kwargs):
if created:
deliver_event(instance, 'package-created')
post_save.connect(signal_receiver, Package)
When database transaction succeeds, in short when transaction.on_commit()
, deliver_event
must be triggered.
Subscribed users now can be informed that a package created if they have created a Webhook
.
import requests
requests.post(
url='https://your-app.com/whisperer/hooks/',
headers={
'Authorization': 'Token <secret-login-token>',
},
json={
'event_type': 'package-created',
'secret_key': 'secret',
'target_url': 'https://example.com/',
}
)
When a package created, uuid
, type
& data
passed through PackageSerializer
will be posted to https://example.com/.
import requests
requests.post(
url='https://example.com/',
headers={
'Content-Type': 'application/json',
'X-Whisperer-Event': 'package-created',
},
json={
'event': {
'type': 'package-created',
'uuid': 'da81e85139824c6187dd1e58a7d3f971',
},
'data': {
'id': 61,
'transfer_id': 49,
'order_number': '248398923123',
'.....': '......',
}
}
)
In order to cancel the subscription:
import requests
requests.delete(
url='https://your-app.com/whisperer/hooks/<webhook-id>/',
headers={
'Authorization': 'Token <secret-login-token>',
}
)
To re-trigger events that lost on the queue you must call whisperer.tasks.trigger_event_queue_events
with scheduler
To automate the removal of outdated event records, schedule the task whisperer.tasks.delete_outdated_webhook_events
using a scheduler. By default, it targets records older than 12 weeks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dj-whisperer-0.3.8.tar.gz
.
File metadata
- Download URL: dj-whisperer-0.3.8.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b44e0ae6ab2fcb17ff9fa401fd4392fa7390e3ad7eb7fdcfbef0959dd2ccd133 |
|
MD5 | 18313f8c7ca0f6d72a3c8c7f3a3429a5 |
|
BLAKE2b-256 | 63757682a84bdddcd93725964ace4f1956212c23bd8e9e7f5c82199334de895a |
File details
Details for the file dj_whisperer-0.3.8-py3-none-any.whl
.
File metadata
- Download URL: dj_whisperer-0.3.8-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1693e6d12bc4030d7a711f5be63c7004adbb415f284ac9471a05cb99ed1f315d |
|
MD5 | cfb9995d134222a87811f688c2657ccf |
|
BLAKE2b-256 | ded5ae0792bbab62820008d0c349da28b828a1d0bdbae683619f400142df4716 |