I am using crontab in django and my OS is ubuntu
def my_scheduled_job():
print("1")
This is code in settings.py
CRONJOBS = [
('*/1 * * * *', 'stocks.cron.my_scheduled_job')
]
If I run
python3 manage.py crontab run #with hash
it runs the function and print it, but it does not run when I run server. What should I do.
It was my code in crontab
crontab -e
*/1 * * * * /usr/bin/python3 /home/stockstelegraph/manage.py crontab run 6b918d2422a9f4fce735a3383cee6485 # django-cronjobs
Your code actually works. You may be think that
print("1")
should appear in stdout? So it doesn't work that way, because cron doesn't usestdour
andstderr
for it's output. To see actual results you should point path to some log file inCRONJOBS
list: just put'>> /path/to/log/file.log'
as last argument, e.g: