【问题标题】:Periodic tasks not working in Django Celery定期任务在 Django Celery 中不起作用
【发布时间】:2012-12-20 08:14:32
【问题描述】:

这是我的定期任务:

from celery.task import PeriodicTask
from celery.registry import tasks
from datetime import timedelta
from datetime import datetime

class MyTask(PeriodicTask):
    run_every = timedelta(minutes=1)

    def run(self, **kwargs):
        self.get_logger().info("Time now: " + datetime.now())
        print("Time now: " + datetime.now())

tasks.register(MyTask)

我在 python manage.py runserver 启动了我的 django 服务器,还使用 ​​python manage.py celeryd -B 启动了 celery。

尽管根据代码,命令提示符上仍然没有打印任何内容,应该已经打印了时间。

知道这里出了什么问题吗?看起来很直接。

【问题讨论】:

  • 你解决了吗?

标签: python django celery


【解决方案1】:

检查您的系统时区是否与 Django 时区相同。

对于 Django:从设置文件中更改它。

对于 linux 操作系统:改成这样:ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

【讨论】:

    【解决方案2】:

    你应该有类似的东西:

    CELERYBEAT_SCHEDULE = {
        'proc': {
            "task": "tasks.processing",
            "schedule": timedelta(seconds=60),
            },
        }
    

    在您的 celeryconfig.py 或 django 的 settings.py 中 在此处查看完整文档http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 2017-06-15
      • 2014-02-23
      • 2017-03-19
      • 1970-01-01
      • 2017-01-06
      • 2013-12-05
      • 2022-01-01
      • 2012-05-09
      相关资源
      最近更新 更多