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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dj-whisperer-0.5.1.tar.gz.
File metadata
- Download URL: dj-whisperer-0.5.1.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf508a2e60faf281b163897e64bf914ce1ffd362ae86cfc942b92a4a3f55cbc8
|
|
| MD5 |
7695b5b91ce478b6bf369e02e298d783
|
|
| BLAKE2b-256 |
4eced6776f49e79589568c001c77c952d625518085d62c0e80ff14e9655a982c
|
File details
Details for the file dj_whisperer-0.5.1-py3-none-any.whl.
File metadata
- Download URL: dj_whisperer-0.5.1-py3-none-any.whl
- Upload date:
- Size: 25.2 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 |
2839a0bd183ca13aa9b708f780c1cc18ba18bf7bbacb168322e0942635511a21
|
|
| MD5 |
e220330b6530ec1a9e56f61d557fa8be
|
|
| BLAKE2b-256 |
12d6db4960160cab12eaa0f3a0b353d32e9b5062969bf4940bc1491cf7c82b07
|