我已经使用 https://pypi.org/project/django-crontab/ 教程来安排玉米作业,但它不起作用: 我加了
INSTALLED_APPS = [
...,
'django_crontab',
]
CRONJOBS = [
('*/1 * * * *', 'allActivitiesApp.cron.sendNotification', '>> /path/to/log/file.log'),
]
在 allActivitiesApp ->corn.py:
from .models import *
def sendNotification():
# notificationList = dateBasedNotificaton.objects.filter(scheduleDate = date.today())
obj = test(name="working")
obj.save()
obj.refresh_from_db()
# print("sending notifications/messages")
return "success"
但是当我尝试获取我发现的日志时它没有做任何事情:
Feb 1 13:17:01 karanyogi CRON[43137]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 13:17:01 karanyogi CRON[43138]: (karanyogi) CMD (/home/karanyogi/E-Mango/env/bin/python /home/karanyogi/E-Mango/Jan27New/eMango/manage.py crontab run 60a198cfdc0c719d07735a708d42bafb >> /path/to/log/file.log # django-cronjobs for iStudyMain)
Feb 1 13:17:01 karanyogi CRON[43136]: (karanyogi) MAIL (mailed 71 bytes of output but got status 0x004b from MTA#012)
Feb 1 13:18:01 karanyogi CRON[43267]: (karanyogi) CMD (/home/karanyogi/E-Mango/env/bin/python /home/karanyogi/E-Mango/Jan27New/eMango/manage.py crontab run 60a198cfdc0c719d07735a708d42bafb >> /path/to/log/file.log # django-cronjobs for iStudyMain)
Feb 1 13:18:01 karanyogi CRON[43266]: (karanyogi) MAIL (mailed 71 bytes of output but got status 0x004b from MTA#012)
Feb 1 13:19:01 karanyogi CRON[43285]: (karanyogi) CMD (/home/karanyogi/E-Mango/env/bin/python /home/karanyogi/E-Mango/Jan27New/eMango/manage.py crontab run 60a198cfdc0c719d07735a708d42bafb >> /path/to/log/file.log # django-cronjobs for iStudyMain)
Feb 1 13:19:01 karanyogi CRON[43282]: (karanyogi) MAIL (mailed 71 bytes of output but got status 0x004b from MTA#012)
Feb 1 13:20:01 karanyogi CRON[43437]: (karanyogi) CMD (/home/karanyogi/E-Mango/env/bin/python /home/karanyogi/E-Mango/Jan27New/eMango/manage.py crontab run 60a198cfdc0c719d07735a708d42bafb >> /path/to/log/file.log # django-cronjobs for iStudyMain)
Feb 1 13:20:01 karanyogi CRON[43436]: (karanyogi) MAIL (mailed 71 bytes of output but got status 0x004b from MTA#012)
Feb 1 13:21:01 karanyogi CRON[43789]: (karanyogi) CMD (/home/karanyogi/E-Mango/env/bin/python /home/karanyogi/E-Mango/Jan27New/eMango/manage.py crontab run 60a198cfdc0c719d07735a708d42bafb >> /path/to/log/file.log # django-cronjobs for iStudyMain)
Feb 1 13:21:01 karanyogi CRON[43788]: (karanyogi) MAIL (mailed 71 bytes of output but got status 0x004b from MTA#012)
Feb 1 13:22:01 karanyogi CRON[43809]: (karanyogi) CMD (/home/karanyogi/E-Mango/env/bin/python /home/karanyogi/E-Mango/Jan27New/eMango/manage.py crontab run 60a198cfdc0c719d07735a708d42bafb >> /path/to/log/file.log # django-cronjobs for iStudyMain)
Feb 1 13:22:01 karanyogi CRON[43808]: (karanyogi) MAIL (mailed 71 bytes of output but got status 0x004b from MTA#012)
我在邮件中没有收到任何日志。
我该如何解决这个问题...?
答案 0 :(得分:0)
我认为您的文件名有问题:
In allActivitiesApp -> corn.py:
文件名应该是 cron.py
而不是 corn.py
。
第二个原因可能是您没有运行命令:
python manage.py crontab add
将所有定义的作业从 CRONJOBS 添加到 crontab
要显示此项目的当前活动作业:
python manage.py crontab show