Name | dj-raincheck JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | Simple asynchronous execution for Django |
upload_time | 2025-08-23 19:05:13 |
maintainer | None |
docs_url | None |
author | Aron Jones, Adam Hill |
requires_python | >=3.10 |
license | The MIT License (MIT) Copyright (c) 2013 defrex Copyright (c) 2025 adamghill Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
django
web
request
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# dj-raincheck βοΈ
> Schedule functions to run after a request in Django without additional infrastructure.
Background tasks are great, but they are often overpowered for certain tasks and can require additional services. `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.
## Installation π»
```shell
uv add dj-raincheck
OR
pip install dj-raincheck
```
## Usage π§βπ§
1. Add `dj_raincheck` to your `INSTALLED_APPS` in `settings.py`.
```python
# settings.py
INSTALLED_APPS = (
...
"dj_raincheck",
)
```
2. Create a function that you want to run after the current request/response lifecycle.
```python
# 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])
```
3. Queue the function in view code to be run after the current request/response lifecycle by calling its `schedule` method and passing in the necessary args or kwargs.
```python
# 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.
## How does this work? β¨
1. `dj-raincheck` attaches a callback to the [`request_finished`](https://docs.djangoproject.com/en/stable/ref/signals/#django.core.signals.request_finished) signal provided by Django
2. Using the `@raincheck` decorator adds a `schedule` function to the original function
3. Calling `schedule()` queues the original function, args, and kwargs
4. When the current request is complete, `dj-raincheck` pops all scheduled functions from the queue and starts a new thread for each one
## Drawbacks π’
`dj-raincheck` does not persist data to the disk or a database, so there are no guarantees if will be executed if the current request thread hangs or dies.
This is an explicit design trade-off to provide operational simplicity. `dj-raincheck` is useful for "fire-and-forget" tasks which, if they happen to fail, would be ok. If an application requires transactional guarantees, I recommend using [django-tasks](https://github.com/RealOrangeOne/django-tasks) instead.
## Supported Webservers πΈοΈ
- β
Django development server
- β
`gunicorn`
- π€· `uWSGI` (might require [enabling threads](https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#a-note-on-python-threads))
Please make a PR for other production webservers with your findings.
## Inspiration π
- Forked from [django-after-response](https://github.com/defrex/django-after-response)
Raw data
{
"_id": null,
"home_page": null,
"name": "dj-raincheck",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "django, web, request",
"author": "Aron Jones, Adam Hill",
"author_email": "Aron Jones <aron.jones@gmail.com>, Adam Hill <adam@adamghill.com>",
"download_url": "https://files.pythonhosted.org/packages/88/c3/567791fff017aef8dfd83327b25b52c66af68ec067f14cbc3659d9d80f6a/dj_raincheck-0.4.0.tar.gz",
"platform": null,
"description": "# dj-raincheck \u2614\ufe0f\n\n> Schedule functions to run after a request in Django without additional infrastructure.\n\nBackground tasks are great, but they are often overpowered for certain tasks and can require additional services. `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.\n\n## Installation \ud83d\udcbb\n\n```shell\nuv add dj-raincheck\n\nOR\n\npip install dj-raincheck\n```\n\n## Usage \ud83e\uddd1\u200d\ud83d\udd27\n\n1. Add `dj_raincheck` to your `INSTALLED_APPS` in `settings.py`.\n\n```python\n# settings.py\n\nINSTALLED_APPS = (\n ...\n \"dj_raincheck\",\n)\n```\n\n2. Create a function that you want to run after the current request/response lifecycle.\n\n```python\n# tasks.py\n\nfrom django.core.mail import send_mail\nfrom dj_raincheck import raincheck\n\n@raincheck\ndef send_email(to: str, subject: str, body: str) -> None:\n send_mail(subject, body, 'me@example.com', [to])\n```\n\n3. Queue the function in view code to be run after the current request/response lifecycle by calling its `schedule` method and passing in the necessary args or kwargs.\n\n```python\n# views.py\n\nfrom .tasks import send_email\n\n# Function-based view example\ndef index(request):\n ...\n\n send_email.schedule('customer@example.com', 'Confirm Signup', body)\n\n return render(...)\n\n# Class-based view example\nclass IndexView(View):\n def get(self, request, *args, **kwargs):\n ...\n \n send_email.schedule('customer@example.com', 'Confirm Signup', body)\n\n return render(...)\n```\n\n## Settings \u2699\ufe0f\n\n### `RAINCHECK_RUN_ASYNC`\n\n`True` by default. Set to `False` to execute the jobs in the current thread as opposed to starting a new thread for each function.\n\nNOTE: 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.\n\n### `RAINCHECK_IMMEDIATE`\n\n`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.\n\nNOTE: When set to `True`, functions will execute synchronously during the request/response cycle.\n\n## How does this work? \u2728\n\n1. `dj-raincheck` attaches a callback to the [`request_finished`](https://docs.djangoproject.com/en/stable/ref/signals/#django.core.signals.request_finished) signal provided by Django\n2. Using the `@raincheck` decorator adds a `schedule` function to the original function\n3. Calling `schedule()` queues the original function, args, and kwargs\n4. When the current request is complete, `dj-raincheck` pops all scheduled functions from the queue and starts a new thread for each one\n\n## Drawbacks \ud83d\ude22\n\n`dj-raincheck` does not persist data to the disk or a database, so there are no guarantees if will be executed if the current request thread hangs or dies.\n\nThis is an explicit design trade-off to provide operational simplicity. `dj-raincheck` is useful for \"fire-and-forget\" tasks which, if they happen to fail, would be ok. If an application requires transactional guarantees, I recommend using [django-tasks](https://github.com/RealOrangeOne/django-tasks) instead.\n\n## Supported Webservers \ud83d\udd78\ufe0f\n\n- \u2705 Django development server\n- \u2705 `gunicorn`\n- \ud83e\udd37 `uWSGI` (might require [enabling threads](https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#a-note-on-python-threads))\n\nPlease make a PR for other production webservers with your findings.\n\n## Inspiration \ud83d\ude4f\n\n- Forked from [django-after-response](https://github.com/defrex/django-after-response)\n",
"bugtrack_url": null,
"license": "The MIT License (MIT) Copyright (c) 2013 defrex Copyright (c) 2025 adamghill Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Simple asynchronous execution for Django",
"version": "0.4.0",
"project_urls": {
"homepage": "https://github.com/adamghill/dj-raincheck/",
"repository": "https://github.com/adamghill/dj-raincheck.git"
},
"split_keywords": [
"django",
" web",
" request"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "325324cfbabc853b26ba15c6627743be7f0a74f16e7b40d8ea38dd400a265ab2",
"md5": "bf342fa8dfed081b7e61027f685d1f14",
"sha256": "dc988faf7676ed62ab044724fcf5e9c9a3d39fb262a8f1ebf736c71920000ebc"
},
"downloads": -1,
"filename": "dj_raincheck-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf342fa8dfed081b7e61027f685d1f14",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 6122,
"upload_time": "2025-08-23T19:05:11",
"upload_time_iso_8601": "2025-08-23T19:05:11.979280Z",
"url": "https://files.pythonhosted.org/packages/32/53/24cfbabc853b26ba15c6627743be7f0a74f16e7b40d8ea38dd400a265ab2/dj_raincheck-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "88c3567791fff017aef8dfd83327b25b52c66af68ec067f14cbc3659d9d80f6a",
"md5": "28007b11636fcf0be23c347bcc810fab",
"sha256": "b4f005737405a8c19ab4ab5845df39a68b490b947f658d99421eb77e82f7dac7"
},
"downloads": -1,
"filename": "dj_raincheck-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "28007b11636fcf0be23c347bcc810fab",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 5292,
"upload_time": "2025-08-23T19:05:13",
"upload_time_iso_8601": "2025-08-23T19:05:13.105656Z",
"url": "https://files.pythonhosted.org/packages/88/c3/567791fff017aef8dfd83327b25b52c66af68ec067f14cbc3659d9d80f6a/dj_raincheck-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-23 19:05:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adamghill",
"github_project": "dj-raincheck",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "dj-raincheck"
}