Django Simple Task
django-simple-task runs background tasks in Django 3 without requiring other services and workers. It runs them in the same event loop as your ASGI application. It is not resilient as a proper task runner such as Celery, but works for some simple tasks and has less overall overheads.
Guide
Install the package:
pip install django-simple-task
Added it to installed apps:
# settings.py
INSTALLED_APPS = [
...
'django_simple_task'
]
Apply ASGI middleware :
# asgi.py
from django_simple_task import django_simple_task_middlware
application = django_simple_task_middlware(application)
Call a background task in Django view:
from django_simple_task import defer
def task1():
time.sleep(1)
print("task1 done")
async def task2():
await asyncio.sleep(1)
print("task2 done")
def view(requests):
defer(task1)
defer(task2)
return HttpResponse(b"My View")
It is required to run Django with ASGI server. Official Doc
Configurations
Concurrency level can be controlled by adding DJANGO_SIMPLE_TASK_WORKERS to settings. Defaults to 1.
Metadata
Release files for django-simple-task 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-simple-task-0.1.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_simple_task-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / django-simple-task-0.1.2.tar.gz
| Download URL | django-simple-task-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c70c5fd1db9ba58026ea3a00831c2c1a4d335f29c106321bb2dce643b7a71319
|
|
BLAKE2b-256 checksum How to use checksums |
5fbaabc186afbb92f5e10a46967afd58e31d66abea6421fd645fbec598ff3ba1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.2 Linux/5.6.12-1-MANJARO
|
Release files / django_simple_task-0.1.2-py3-none-any.whl
| Download URL | django_simple_task-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe6494f5297711f5ec767835163dad3e4f6b751aa8857f0c338e5271a0721a4f
|
|
BLAKE2b-256 checksum How to use checksums |
827893daa3c370c297ada1c5a8eec16b85022cb311a14c3138b4319135346361
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.2 Linux/5.6.12-1-MANJARO
|