Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery worker and command line args

Tags:

python

celery

I am refactoring my code to use celery worker.

Before I used to use argparse to pass command line args.

e.g.

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

How can I add?

I don't want to use environment variable if I don't have to.

e.g export environment=development
like image 505
Tampa Avatar asked Jan 26 '14 15:01

Tampa


1 Answers

The Celery worker does not execute your __main__.

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

like image 175
asksol Avatar answered Sep 27 '22 20:09

asksol