<i id='utqDL'><tr id='utqDL'><dt id='utqDL'><q id='utqDL'><span id='utqDL'><b id='utqDL'><form id='utqDL'><ins id='utqDL'></ins><ul id='utqDL'></ul><sub id='utqDL'></sub></form><legend id='utqDL'></legend><bdo id='utqDL'><pre id='utqDL'><center id='utqDL'></center></pre></bdo></b><th id='utqDL'></th></span></q></dt></tr></i><div id='utqDL'><tfoot id='utqDL'></tfoot><dl id='utqDL'><fieldset id='utqDL'></fieldset></dl></div>
      <bdo id='utqDL'></bdo><ul id='utqDL'></ul>
  1. <legend id='utqDL'><style id='utqDL'><dir id='utqDL'><q id='utqDL'></q></dir></style></legend>

    1. <small id='utqDL'></small><noframes id='utqDL'>

    2. <tfoot id='utqDL'></tfoot>

      设置计划的工作?

      时间:2024-04-20

        <bdo id='yCvfD'></bdo><ul id='yCvfD'></ul>

        <tfoot id='yCvfD'></tfoot>

        1. <i id='yCvfD'><tr id='yCvfD'><dt id='yCvfD'><q id='yCvfD'><span id='yCvfD'><b id='yCvfD'><form id='yCvfD'><ins id='yCvfD'></ins><ul id='yCvfD'></ul><sub id='yCvfD'></sub></form><legend id='yCvfD'></legend><bdo id='yCvfD'><pre id='yCvfD'><center id='yCvfD'></center></pre></bdo></b><th id='yCvfD'></th></span></q></dt></tr></i><div id='yCvfD'><tfoot id='yCvfD'></tfoot><dl id='yCvfD'><fieldset id='yCvfD'></fieldset></dl></div>

            <small id='yCvfD'></small><noframes id='yCvfD'>

            • <legend id='yCvfD'><style id='yCvfD'><dir id='yCvfD'><q id='yCvfD'></q></dir></style></legend>

                  <tbody id='yCvfD'></tbody>
              1. 本文介绍了设置计划的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一直在使用 Django 开发一个网络应用程序,我很好奇是否有办法安排作业定期运行.

                I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically.

                基本上我只是想通过数据库运行并定期自动进行一些计算/更新,但我似乎找不到任何关于这样做的文档.

                Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.

                有人知道怎么设置吗?

                澄清一下:我知道我可以设置一个 cron 作业来执行此操作,但我很好奇 Django 中是否有提供此功能的功能.我希望人们能够自己部署此应用,而无需进行太多配置(最好是零).

                To clarify: I know I can set up a cron job to do this, but I'm curious if there is some feature in Django that provides this functionality. I'd like people to be able to deploy this app themselves without having to do much config (preferably zero).

                我考虑过追溯"触发这些操作,只需检查自上次向站点发送请求后是否应该运行作业,但我希望有一些更简洁的东西.

                I've considered triggering these actions "retroactively" by simply checking if a job should have been run since the last time a request was sent to the site, but I'm hoping for something a bit cleaner.

                推荐答案

                我采用的一个解决方案是:

                One solution that I have employed is to do this:

                1) 创建一个 自定义管理命令,例如

                1) Create a custom management command, e.g.

                python manage.py my_cool_command
                

                2) 使用 cron(在 Linux 上)或 at(在 Windows 上)在需要的时间运行我的命令.

                2) Use cron (on Linux) or at (on Windows) to run my command at the required times.

                这是一个简单的解决方案,不需要安装繁重的 AMQP 堆栈.但是,使用其他答案中提到的芹菜之类的东西有很多好处.特别是,使用 Celery 时,不必将应用程序逻辑分散到 crontab 文件中是一件好事.但是,cron 解决方案非常适合中小型应用程序,并且您不希望有很多外部依赖项.

                This is a simple solution that doesn't require installing a heavy AMQP stack. However there are nice advantages to using something like Celery, mentioned in the other answers. In particular, with Celery it is nice to not have to spread your application logic out into crontab files. However the cron solution works quite nicely for a small to medium sized application and where you don't want a lot of external dependencies.

                在更高版本的 Windows 中,Windows 8、Server 2012 及更高版本已弃用 at 命令.您可以使用 schtasks.exe 进行相同的用途.

                In later version of windows the at command is deprecated for Windows 8, Server 2012 and above. You can use schtasks.exe for same use.

                **** 更新 ****这是新的 链接用于编写自定义管理命令的 django doc

                **** UPDATE **** This the new link of django doc for writing the custom management command

                这篇关于设置计划的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:SyntaxError:解析时出现意外的 EOF 下一篇:Django中null=True和blank=True有什么区别?

                相关文章

                <tfoot id='0oBgx'></tfoot>
                  <bdo id='0oBgx'></bdo><ul id='0oBgx'></ul>

                <legend id='0oBgx'><style id='0oBgx'><dir id='0oBgx'><q id='0oBgx'></q></dir></style></legend>

                  <small id='0oBgx'></small><noframes id='0oBgx'>

                  1. <i id='0oBgx'><tr id='0oBgx'><dt id='0oBgx'><q id='0oBgx'><span id='0oBgx'><b id='0oBgx'><form id='0oBgx'><ins id='0oBgx'></ins><ul id='0oBgx'></ul><sub id='0oBgx'></sub></form><legend id='0oBgx'></legend><bdo id='0oBgx'><pre id='0oBgx'><center id='0oBgx'></center></pre></bdo></b><th id='0oBgx'></th></span></q></dt></tr></i><div id='0oBgx'><tfoot id='0oBgx'></tfoot><dl id='0oBgx'><fieldset id='0oBgx'></fieldset></dl></div>