defrex/django-after-response

Simple asynchronous execution

Build Status Pypi Package

Django After Response

Simple asynchronous execution.

Tools like Celery are great, but often they are overpowered for the task at hand, and come with lots of requirements like daemons and task queues.

After Response is a simple alternative. It will execute code after the request is complete, without the need for additional daemons or task queues.

Usage

$ pip install django-after-response

Add after_response to your INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'after_response',
)

Decorate your function.

from django.core.mail import send_mail
import after_response

@after_response.enable
def my_email_task(to, subject, body):
    send_mail(subject, body, '[email protected]', [to])

Then, when you want to execute the function after the current request/response.

my_email_task.after_response('[email protected]', 'Confirm Signup', body)

That's it! Execution of your function will be deferred until after the current request/response.

Setting

Set AFTER_RESPONSE_RUN_ASYNC to False to prevent After Response from executing the jobs in another thread. Please note that this is purely for ease of debugging. With threading disabled Django will wait for the task to complete before closing the request.

Stars
126
100.00% more than last month
Forks
16
Open Issues
7