如何获取运行芹菜工人的名称?

发布于 2025-02-13 07:57:40 字数 767 浏览 1 评论 0原文

我想特别关闭芹菜工人。我正在使用app.control.broadcast('shutdown');但是,这将关闭所有工人;因此,我想传递目标参数。

当我运行PS -EF | GREP芹菜,我可以在该过程中看到- 主机名

我知道该格式为{celeryd_nodes} {nodename_sep} {hostName} 来自实用程序函数 nodeName

destination =  ''.join(['celery', # CELERYD_NODES defined at /etc/default/newfies-celeryd
                        '@', # from celery.utils.__init__ import NODENAME_SEP
                         socket.gethostname()])

是否有返回nodeName的辅助功能?我不想自己创建它,因为我不想将值进行编码。

I want to shut down celery workers specifically. I was using app.control.broadcast('shutdown'); however, this shutdown all the workers; therefore, I would like to pass the destination parameter.

When I run ps -ef | grep celery, I can see the --hostname on the process.

I know that the format is {CELERYD_NODES}{NODENAME_SEP}{hostname} from the utility function nodename

destination =  ''.join(['celery', # CELERYD_NODES defined at /etc/default/newfies-celeryd
                        '@', # from celery.utils.__init__ import NODENAME_SEP
                         socket.gethostname()])

Is there a helper function which returns the nodename? I don't want to create it myself since I don't want to hardcode the value.

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

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

发布评论

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

评论(1

魂ガ小子 2025-02-20 07:57:40

我不确定这是否是您要寻找的,但是使用

app = Celery('app_name', broker=...)
app.control.inspect().stats()  # statistics per worker
app.control.inspect().registered()  # registered tasks per each worker
app.control.inspect().active()  # active workers/tasks

​每个人的工人:

app.control.inspect().stats().keys()
app.control.inspect().registered().keys()
app.control.inspect().active().keys()

例如:

>>> app.control.inspect().registered().keys()
dict_keys(['worker1@my-host-name', 'worker2@my-host-name', ..])

I am not sure if that's what you're looking for, but with control.inspect you can get info about the workers, for example:

app = Celery('app_name', broker=...)
app.control.inspect().stats()  # statistics per worker
app.control.inspect().registered()  # registered tasks per each worker
app.control.inspect().active()  # active workers/tasks

so basically you can get the list of workers from each one of them:

app.control.inspect().stats().keys()
app.control.inspect().registered().keys()
app.control.inspect().active().keys()

for example:

>>> app.control.inspect().registered().keys()
dict_keys(['worker1@my-host-name', 'worker2@my-host-name', ..])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文