python - 如何立即运行 celery 时间表?

标签 python django celery celerybeat

我有一个配置如下的 celery 时间表:

CELERYBEAT_SCHEDULE = {
    "runs-every-30-seconds": {
        "task": "tasks.refresh",
        "schedule": timedelta(hours=1)
    },
}

经过测试,我发现这个调度是在1小时后启动的,但我想立即运行这个调度,并在1小时后再次运行。

最佳答案

如果您的意思是在启动时,请在 AppConfig.ready() 中执行(django 1.7 中的新功能):

# my_app/__init__.py:

class MyAppConfig(AppConfig):
    def ready(self):
        tasks.refresh.delay()

另见:https://docs.djangoproject.com/en/1.7/ref/applications/#module-django.apps

如果您只是为了测试而这样做,我宁愿直接调用/延迟任务而不是测试 celery 调度程序本身。

关于python - 如何立即运行 celery 时间表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23098269/

相关文章:

python - 使用多个分隔符有效地拆分字符串并保留每个分隔符?

python - 类型错误:url() 获得意外的关键字参数 'name_space'

python - "Branch Predictions"和高级语言中的马尔可夫链

python - Django如何关闭警告

python - celery 的 `max_retries` 被命中后会发生什么?

python - 使用FunctionalAPI 时如何装饰我的枚举?

python - 如何使用 ManyToMany 字段填充默认表单数据?

python - 如何使用Sphix的sphinx.ext.coverage的coverage_show_missing_items?

python - 使用 Flask 和 SQLAlchemy 的 Celery 任务中的数据库未更新

不同 docker 容器之间的 Django channel