简体   繁体   English

Django中的预定任务

[英]Scheduled task in django

I need explanation for scheduled task 我需要计划任务的解释

I need to run task in every end of the day automatically like cron 我需要像cron这样在一天的每一天自动运行任务

I tried schedule app in my project 我在项目中尝试了计划应用

import schedule
import time

def job():
    pprint.pprint("I'm working...")

schedule.every(10).minutes.do(job)


while True:
    schedule.run_pending()
    time.sleep(1)

when i add above code in project site was loading continuously 当我在项目站点中添加以上代码时,持续加载

Question: Need to create task run automatically in background without user knowledge and without any command? 问题:是否需要创建在没有用户知识和任何命令的情况下在后台自动运行的任务? It is possible? 有可能的?

I am new for python and django 我是python和Django的新手

Please suggest any idea for this task 请提出关于此任务的任何想法

If it is not an overkill - I recommend Celery . 如果不是太强了,我建议芹菜
It has "Celerybeat" which is like "cron" 它具有“ Celerybeat”,就像“ cron”

Actually I think this is exactly what you need. 实际上,我认为这正是您所需要的。

通常,您创建一个管理命令( https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ )并从cron作业中运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM