I have following:
python manage.py crontab show # this command give following
Currently active jobs in crontab:
12151a7f59f3f0be816fa30b31e7cc4d -> ('*/1 * * * *', 'media_api_server.cron.cronSendEmail')
My app is in virtual environment (env) active
In my media_api_server/cron.py I have following function:
def cronSendEmail():
print("Hello")
return true
In settings.py module:
INSTALLED_APPS = (
......
'django_crontab',
)
CRONJOBS = [
('*/1 * * * *', 'media_api_server.cron.cronSendEmail')
]
To me all defined in place but when I run python manage.py runserver in virtual environment, console doesn't print any thing.
System check identified no issues (0 silenced).
July 26, 2016 - 12:12:52
Django version 1.8.1, using settings 'mediaserver.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
'Django-crontab' module is not working I followed its documentation here https://pypi.python.org/pypi/django-crontab
Your code actually works. You may be think that print("Hello")
should appear in stdout? So it doesn't work that way, because cron doesn't use stdour
and stderr
for it's output. To see actual results you should point path to some log file in CRONJOBS
list: just put '>> /path/to/log/file.log'
as last argument, e.g:
CRONJOBS = [
('*/1 * * * *', 'media_api_server.cron.cronSendEmail', '>> /path/to/log/file.log')
]
Also it might be helpful to redirect your errors to stdout too. For this you heed to add CRONTAB_COMMAND_SUFFIX = '2>&1'
to your settings.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With