升级芹菜4.xx到django app中的5.xx -execute_from_commandline()替换
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在这里做一些事情。
https://stackoverflow.com/a/65075395/6043170”中调用/启动工人的典型方法。
从python
要执行
celeryCommand
/click.command
,您将参数传递到main
函数,您仍然负责控制芹菜如何退出这种情况也是如此。您可以选择一个动词
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:
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 themain
functionYou would still be responsible for controlling how celery exits in this case, too. You may choose a verb other than
worker
such asmulti
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.