停止 Celery 缓存 Django 模板

问题描述 投票:0回答:1

我通过 RabbitMQ 代理设置了 Django 3.24、celery 4.4.7 和 celerybeat 2.2.0。

我有一个 celery 任务,可以渲染 Django 模板,然后将其发送给多个电子邮件收件人。

Django 模板是动态的,可以随时对其内容进行更改,从而重写模板。麻烦的是,有时我必须重新启动 celery 才能让它重新读取模板。

我的问题是,有没有办法强制 celery 重新读取模板文件,而不需要完全重启 celery?

芹菜.py

    from __future__ import absolute_import, unicode_literals
    import os
    from celery import Celery

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backoffice.settings')

    app = Celery('backoffice')

    default_config = 'backoffice.celery_config'

    app.config_from_object(default_config)
    app.autodiscover_tasks()


    @app.task(bind=True)
    def debug_task(self):
        print('Request: {0!r}'.format(self.request))

celery_config.py

    from django.conf import settings
    broker_url = "amqp://someusername:somepassword@webserver:5672/backoffice"
    worker_send_task_event = False
    task_ignore_result = True
    task_time_limit = 60
    task_soft_time_limit = 50
    task_acks_late = True
    worker_prefetch_multiplier = 10
    worker_cancel_long_running_tasks_on_connection_loss = True

芹菜命令

celery  -A backoffice worker -B -l info --without-heartbeat --without-gossip --without-mingle
django django-templates celery
1个回答
0
投票

您是否找到了无需自动重新加载的解决方案?有更新吗?

© www.soinside.com 2019 - 2024. All rights reserved.