A middleware for Dramatiq (for Django) that keeps track of task state only when you need it to.
Project description
dramatiq-taskstate
A middleware for Dramatiq (for Django) that keeps track of task state only when you need it to.
Quickstart
-
Install dramatiq-taskstate via pip:
pip install dramatiq-taskstate
Or via the repo:
pip install git+https://github.com/armandtvz/dramatiq-taskstate.git
-
Add
taskstate
to yourINSTALLED_APPS
in your project settings.py file:INSTALLED_APPS = [ 'django_dramatiq', '...', '...', 'taskstate', ]
-
Run migrate:
python manage.py migrate
-
Include the middleware in your
django_dramatiq
configuration:DRAMATIQ_BROKER = { 'BROKER': '...', 'OPTIONS': { # ... }, 'MIDDLEWARE': [ # ... 'taskstate.middleware.StateMiddleware', ] }
-
Add a
for_state
parameter to Dramatiq actors that need task state to be tracked. The middleware will ignore any tasks that don't have this argument. Also remember that all values in thefor_state
dictionary must be JSON serializable.@dramatiq.actor def my_actor(arg, for_state={}): pass
-
Then, when sending a new task to Dramatiq: the
for_state
dictionary can contain any of the following keys:'for_state': { 'user_pk': user.pk, 'model_name': 'model', 'app_name': 'app', 'description': 'description', }
-
Each time the
Task
object is updated atask_changed
signal is dispatched which can be handled like this:from django.dispatch import receiver from taskstate.middleware import StateMiddleware from taskstate.signals import task_changed @receiver(task_changed, sender=StateMiddleware) def handle_task_changed(sender, task, **kwargs): pass
Management commands
The clear_tasks
management command will delete all Task
objects currently
in the database irrespective of status.
python manage.py clear_tasks
Compatibility
- Compatible with Python 3.8 and above.
- Compatible with Django 3.2 and above.
Versioning
This project follows semantic versioning (SemVer).
License and code of conduct
Check the root of the repo for these files.
Project details
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
Hashes for dramatiq_taskstate-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c7c009fda7f5d71a335669e231272681f520413b0aefb3223c4808823ec7cf1 |
|
MD5 | 9058150ba035fb44aa8b64ec4c786e3f |
|
BLAKE2b-256 | e60d65301690beafc0e94721ca89ff01110e4b537b388f58385a27a63582ce69 |