Skip to main content

django-post-request-task

https://circleci.com/gh/mozilla/django-post-request-task.svg?style=svg

A celery task class whose execution is delayed until after the request finishes, using request_started and request_finished signals from django and thread locals.

This is useful if your views are wrapped in transactions (as they should if you’re making database modifications in them), as you can end up triggering a celery task too soon before the transaction has been committed (or even trigger a task when the corresponding transaction has been rolled back).

By listening to the request_started and request_finished django signals, we can safely trigger a task after all transactions created from @atomic or ATOMIC_REQUESTS have been committed.

Usage

from celery import Celery
from post_request_task.task import PostRequestTask


app = Celery('myapp', task_cls=PostRequestTask)

@app.task
def my_task():
    # If .delay() is called on this task inside a django request-response
    # cycle it will be called once the request is finished, and not before.
    pass

Or, if you are using the decorator directly:

from post_request_task.task import shared_task

@shared_task
def my_task():
    pass

That’s it. If the task is called from outside the django request-response cycle, then it will be triggered normally.

As a bonus feature, if the same task is called with the same argument several times during a request-response cycle, it will only be queued up once.

Running tests

$ make testenv
$ make test

By default, tests are run with whatever django version is installed. If you want to run tests for other versions use tox:

$ make testenv
$ tox -e 3.7-2.0.x # or any other environment defined in our tox.ini

Metadata

Release files for django-post-request-task 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-post-request-task 0.5
File Size Uploaded Provenance Actions
django-post-request-task-0.5.tar.gz 6.4 kB Without provenance Details for django-post-request-task-0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-post-request-task 0.5
File Interpreter ABI Platform Actions
django_post_request_task-0.5-py3-none-any.whl Python 3 none any Details for django_post_request_task-0.5-py3-none-any.whl

Total release size: 13.4 kB

Release files / django-post-request-task-0.5.tar.gz

Download URL django-post-request-task-0.5.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
26c03b5d06eb1705b2438bb719575fac4aae7f34c32837480202acad556edb3c
BLAKE2b-256 checksum
How to use checksums
9d5b460cca16a4cfaa2068a823fad46577b725211d30356827a83d3566f35cb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

Release files / django_post_request_task-0.5-py3-none-any.whl

Download URL django_post_request_task-0.5-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91df3893c9551851cd10568ef3b2cf358bd87e8c65dce728c37196a8de34247c
BLAKE2b-256 checksum
How to use checksums
76d7fdc4123b55edb6cc86f4d8d132d5f10b69bad31b999c6ee9d94a8562f6f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

Security for django-post-request-task 0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page