Initializing a worker with arguments using Celery

后端 未结 2 1188
醉酒成梦
醉酒成梦 2021-02-05 23:07

I\'m having issues finding something that seems like it would be relatively simple to me.

I\'m using Celery 3.1 with Python 3 and am wanting to initialize my workers wi

2条回答
  •  盖世英雄少女心
    2021-02-05 23:52

    I would think you could call the script you wrote using command line arguments. Something like the following:

    my_script.py username password
    

    Inside your script, you can have your main function wrapped in an @celery.task or @app.task decorator.

    import sys
    
    from celery import Celery
    
    cel = Celery() # put whatever config info you need in here
    
    @celery.task
    def main():
        username, password = sys.argv[1], sys.argv[2]
    

    Something like that should get you started. Be sure to also check out Python's argparse for more sophisticated argument parsing.

提交回复
热议问题