I've define a Celery
app in a module, and now I want to start the worker from the same module in its __main__
, i.e. by running the module with python -m
instead of celery
from the command line. I tried this:
app = Celery('project', include=['project.tasks'])
# do all kind of project-specific configuration
# that should occur whenever this module is imported
if __name__ == '__main__':
# log stuff about the configuration
app.start(['worker', '-A', 'project.tasks'])
but now Celery thinks I'm running the worker without arguments:
Usage: worker <command> [options]
Show help screen and exit.
Options:
-A APP, --app=APP app instance to use (e.g. module.attr_name)
[snip]
The usage message is the one you get from celery --help
, as if it didn't get a command. I've also tried
app.worker_main(['-A', 'project.tasks'])
but that complains about the -A
not being recognized.
So how do I do this? Or alternatively, how do I pass a callback to the worker to have it log information about its configuration?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…