【发布时间】:2013-04-05 14:14:16
【问题描述】:
我试图让django-cron 工作,但它没有。我按照指令 here 设置我的 cron,但问题是我的作业仅在我在命令行上键入 python manage.py runcrons 时运行,并且作业不是每 5 分钟运行一次。我不知道还能做什么。我已经阅读了crontabs 和chronograph 上的其他文件,但我很困惑。我是否将 crontabs 与 cron 或 chronograph 一起安装,或者仅使用 django-cron 才能使 cron 正常工作。另外,我如何让我的工作自动运行。在文档 here 我读到 Now everytime you run the management command python manage.py runcrons all the crons will run if required. Depending on the application the management command can be called from the Unix crontab as often as required. Every 5 minutes usually works for most of my applications. 。这是什么意思。我在这里想念什么。我迷路了。帮助
Settings.py
CRON_CLASSES = (
"myapp.views.MyCronJob",
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_cron',
'django.contrib.admin',
'django.contrib.admindocs',
'myapp',
)
views.py
from django_cron import CronJobBase, Schedule
class MyCronJob(CronJobBase):
RUN_EVERY_MINS = 10 # every 10 min
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'my_app.my_cron_job' # a unique code
def do(self):
print "10 min Cron"
theJob()
我应该提到我在 windows 平台上使用 pycharm 来运行 django...
【问题讨论】:
-
你找到这个问题的解决方案了吗?
标签: django cron crontab cron-task django-cron