Simple asynchronous execution for Django
Project description
dj-raincheck
Simple asynchronous execution in Django
Background tasks are great, but often they are overpowered for the task at hand, and require more complicated setup.
dj-raincheck is a simpler alternative. It will execute code after the request is complete, without the need for additional background tasks, daemons, or queues.
NOTE: dj-raincheck is a fork of django-after-response which fixes a few bugs, provides a more modern Python package, and support for newer Django versions.
Installation
uv add dj-raincheck
OR
pip install dj-raincheck
Usage
- Add
dj_raincheckto yourINSTALLED_APPSinsettings.py.
# settings.py
INSTALLED_APPS = (
...
"dj_raincheck",
)
- Create a function that you want to run after the current request/response lifecycle.
# tasks.py
from django.core.mail import send_mail
from dj_raincheck import raincheck
@raincheck
def send_email(to: str, subject: str, body: str) -> None:
send_mail(subject, body, 'me@example.com', [to])
- Queue the function in view code to be run after the current request/response lifecycle by calling its
schedulemethod and passing in the necessary args or kwargs.
# views.py
from .tasks import send_email
# Function-based view example
def index(request):
...
send_email.schedule('customer@example.com', 'Confirm Signup', body)
return render(...)
# Class-based view example
class IndexView(View):
def get(self, request, *args, **kwargs):
...
send_email.schedule('customer@example.com', 'Confirm Signup', body)
return render(...)
Settings
RAINCHECK_RUN_ASYNC
True by default. Set to False to execute the jobs in the current thread as opposed to starting a new thread for each function.
NOTE: This is primarily for debugging purposes. When set to False, Django will wait for all scheduled functions to complete before closing the request, which can significantly increase response times.
RAINCHECK_IMMEDIATE
False by default. Set to True to execute scheduled functions immediately when schedule() is called, rather than queuing them to run after the response is completed.
NOTE: When set to True, functions will execute synchronously during the request/response cycle.
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_raincheck-0.3.0.tar.gz.
File metadata
- Download URL: dj_raincheck-0.3.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f3576abd2fb52e2363cc9deb8204d592a2f754867fc479675350ac82a56dc8d
|
|
| MD5 |
0d04c61569fd9a7126a987d26e00785f
|
|
| BLAKE2b-256 |
0b4a6d33298ac2804bec084dcf77eb57ba69e707bb8a986cb9e78fd9f6942165
|
File details
Details for the file dj_raincheck-0.3.0-py3-none-any.whl.
File metadata
- Download URL: dj_raincheck-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6f69310a14ceb7f7f167f23d6a0c15d401781e8f36af172a16bb5c0ae340763
|
|
| MD5 |
be7984094ef769a35f21b790c090a521
|
|
| BLAKE2b-256 |
c97bd9c8f71b67c61e91c97229fdd9b4b833d0a8ec8668d68dd8ef60d34c2a64
|