2👍
✅
You can use built-in Django commands to avoid third party integrations or external libraries.
For example you can add the following in a my_app/management/commands/my_scheduled_job.py
file:
from django.core.mail import send_mail
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
# ... do the job here
send_mail(
# ...
)
print('Successfully sent')
and then you can just configure your crontab command as usual, for example every day at 8PM:
0 20 * * * python manage.py my_scheduled_job
Here additional info about custom Django commands.
👤Dos
0👍
Take a look at django-mailer:
https://github.com/pinax/django-mailer
It can replace the standard email backend and stores message queue in the db (so no Celery needed).
You just schedule it’s management command through regular cron and that’s basically it.
- [Django]–bash: createdb: command not found
- [Django]-Factory boy error : ValueError: save() prohibited to prevent data loss due to unsaved related object
- [Django]-Skipping step x to step y and validate step x data
- [Django]-Django – Correct way to pass arguments to CBV decorators?
- [Django]-How to do related questions autopopulate
Source:stackexchange.com