升级芹菜4.xx到django app中的5.xx -execute_from_commandline()替换

发布于 2025-01-29 14:16:30 字数 948 浏览 3 评论 0原文

4.xx中的用法如下:

from tenant_schemas_celery.app import CeleryApp

class TenantCeleryApp(CeleryApp):
    def create_task_cls(self):
        return self.subclass_with_self('...', abstract=True, name='...', attribute='_app')

tenant_celery = TenantCeleryApp()
base = celery.CeleryCommand(app=tenant_celery)
base.execute_from_commandline('...')
...

现在,将芹菜液体更新为5.xx时,以下错误显示:

  base = celery.celeryCommand(app = tenant_celery) 
typeError:__init __()有一个意外的关键字参数'app'
 

从文档中,新的芹菜命令使用click.command类,我如何更改代码以适合 - execute_from_commandline ()的替换用法是什么?

编辑: 经过一定的努力,以下代码有效:

tenant_celery.worker_main(argv=['--broker=amqp://***:***@rabbitmq:5672//***',
                                    '-A', f'{__name__}:tenant_celery',
                                    'worker', '-c', '1', '-Q', 'c1,c2,c3,c4'])

the usage in 4.x.x was as following:

from tenant_schemas_celery.app import CeleryApp

class TenantCeleryApp(CeleryApp):
    def create_task_cls(self):
        return self.subclass_with_self('...', abstract=True, name='...', attribute='_app')

tenant_celery = TenantCeleryApp()
base = celery.CeleryCommand(app=tenant_celery)
base.execute_from_commandline('...')
...

Now when updating celery lib to 5.x.x the following error show:

base = celery.CeleryCommand(app=tenant_celery) 
TypeError: __init__() got an unexpected keyword argument 'app'

from the documentation, the new CeleryCommand use click.Command class, how do I change my code to fit - what is the replacement usage for execute_from_commandline()?

EDIT:
after some tries hard the following code works:

tenant_celery.worker_main(argv=['--broker=amqp://***:***@rabbitmq:5672//***',
                                    '-A', f'{__name__}:tenant_celery',
                                    'worker', '-c', '1', '-Q', 'c1,c2,c3,c4'])

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你只要分分秒秒 2025-02-05 14:16:30

您可以在这里做一些事情。


https://stackoverflow.com/a/65075395/6043170”中调用/启动工人的典型方法。

worker = tenant_celery.Worker(
    include=['project.tasks']
)
worker.start()

从python


要执行celeryCommand/click.command,您将参数传递到main函数,

base = CeleryCommand()
base.main(args=['worker', '-A', f'{__name__}:tenant_celery'])

您仍然负责控制芹菜如何退出这种情况也是如此。您可以选择一个动词worker,例如Multi对于您期望打电话的任何芹菜子命令。

您可能还需要明确指定 -A参数的芹菜模块的名称,如下所述

You can do a few things here.


The typical way to invoke / start a worker from within python is discussed at this answer:

worker = tenant_celery.Worker(
    include=['project.tasks']
)
worker.start()

In this case, you would be responsible for making the worker exit when you are done.


To execute the CeleryCommand / click.Command, you pass in the arguments to the main function

base = CeleryCommand()
base.main(args=['worker', '-A', f'{__name__}:tenant_celery'])

You would still be responsible for controlling how celery exits in this case, too. You may choose a verb other than worker such as multi for whatever celery subcommand you were expecting to call.

You may also want to explicitly specify the name of the celery module for the -A parameter as discussed here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文