fle*_*xit 6 django cron crontab cron-task django-cron
我正在努力django-cron工作,但没有。我按照此处的说明设置了我的 cron,但问题是我的作业仅在我python manage.py runcrons在命令行上键入时运行,并且该作业不是每 5 分钟运行一次。我不知道还能做什么。我已经阅读了其他文件crontabs,chronograph但很困惑。我是将 crontabs 与 cron 或计时码表一起安装,还是仅使用 django-cron 就能让 cron 正常工作。还有我如何让我的工作自动运行。在此处的文档中,我阅读了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.. 这是什么意思。我在这里错过了什么。我迷路了。帮助
设置.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',
)
Run Code Online (Sandbox Code Playgroud)
视图.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()
Run Code Online (Sandbox Code Playgroud)
我应该提到我在 Windows 平台上使用 pycharm 来运行 django ...
问题的根源在于操作系统。Web 服务器不是那种调用 cronjobs 的守护进程,它只是处理 Web 请求。要在 Windows 上调用定期任务,您需要使用 Windows 任务计划程序:
解决问题的其他方法是以 celerybeat 模式启动 celery 守护进程。
http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html
这是一种更难的方法,如果您有非常简单的应用程序,则不需要使用 celery。但在很多情况下,队列是最好的解决方案。
| 归档时间: |
|
| 查看次数: |
9297 次 |
| 最近记录: |