0

我必须按时完成任务,因为我使用的是django_cron。 在设定:django_cron只执行一次,调度程序不工作?

INSTALLED_APPS = [ 
    'mailsnake', 
    'corsheaders', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'Avaana_web', 
    'rest_framework', 
    'rest_framework.authtoken', 
    'django_cron', 

] 

和cron.py

from django_cron import CronJobBase, Schedule,cronScheduler 
    import datetime,os 
    class MyCronJob(CronJobBase): 
     RUN_EVERY_MINS = .3 
     RETRY_AFTER_FAILURE_MINS = 5 
     ALLOW_PARALLEL_RUNS = True 
     schedule = Schedule(run_every_mins=RUN_EVERY_MINS,  
    retry_after_failure_mins=RETRY_AFTER_FAILURE_MINS) 
     code = 'my_app.my_cron_job' 
     def do(self): 
      print("hello") 

但是当我只运行

$ python manage.py runcrons 
hello 

一次输出显示并结束。

我如何在每30秒后得到输出。

+0

我也安装了django_cron。通过 $ pip install django_cron –

+0

尝试使用'python -u manage.py runcrons'运行 –

+0

从此链接阅读#6 http://django-cron.readthedocs.io/en/latest/installation.html – Anoop

回答

1

几件事情:

一个。看起来您的cron作业配置不正确。根据文档,你需要在你的设置路径指向创建CRON_CLASSES列表,您的cron类的完全合格的包名,如:

CRON_CLASSES = [ 
    "my_app.cron.MyCronJob", 
    # ... 
] 

湾另外,通过python管理它的意义并不意味着它会继续运行多次。您可能仍然需要从cron作业运行'python manage.py runcrons'。您的日程安排将仅决定当您呼叫manage.py runcron时是否需要运行。在这里看到更多的细节:http://django-cron.readthedocs.io/en/latest/installation.html