Django
,
PyPI:
pip install django-background-tasks
INSTALLED_APPS:
INSTALLED_APPS = (
'background_task',
)
:
python manage.py makemigrations background_task
python manage.py migrate
:
from background_task import background
from django.contrib.auth.models import User
@background(schedule=60)
def notify_user(user_id):
user = User.objects.get(pk=user_id)
user.email_user('Here is a notification', 'You have been notified')
notify_user . , Task . , . , - JSON. , user_id, User.
notify_user 60 :
notify_user(user.id)
( ), :
notify_user(user.id, schedule=90)
notify_user(user.id, schedule=timedelta(minutes=20))
notify_user(user.id, schedule=timezone.now())
:
notify_user.now(user.id)
notify_user = notify_user.now
.
:
notify_user(user.id, verbose_name="Notify user", creator=user)
source
share