芹菜工人和命令行参数 [英] Celery worker and command line args
本文介绍了芹菜工人和命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在重构代码以使用celery worker.
I am refactoring my code to use celery worker.
在我以前使用argparse传递命令行args之前.
Before I used to use argparse to pass command line args.
例如
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Node')
parser.add_argument('--environment', action="store", default='local', help="env e.g. production of development")
environment = arg_options.environment
但是现在我得到了这个错误.
But now I get this error.
celery -A tasks worker --loglevel=info --environment local
celery: error: no such option: --environment
如何添加?
如果不需要,我不想使用环境变量.
I don't want to use environment variable if I don't have to.
e.g export environment=development
推荐答案
芹菜工人不执行您的 __ main __
.
如果要添加其他命令行选项,可以使用 app.user_options
,但请注意,它使用的是 optparse
模块,而不是 argparse
.
If you want to add additional command-line options you can use app.user_options
,
but note that it uses the optparse
module, not argparse
.
有关更多信息,请参见文档中的本节:
See this section in the docs for more:
http://docs.celeryproject.org/en/Latest/userguide/extending.html#preload-options
这篇关于芹菜工人和命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文