Launching flask-rq2 using supervisord
For whatever reason, launching flask-rq2 from supervisord seems to be giving me incredible difficulty which I have never encountered using vanilla rq or even running a Flask app with RQ2 in docker. And of course, it seems that supervisord makes debugging incredibly difficult.
Currently, I have a fairly straight-forward Flask app which is running on an Ubuntu server. Everything is inside a virtual environment, and I am launching as follows:
rq.conf
[program:rq]
directory=/home/<user>/ceams
command=sh boot-workers.sh
process_name=$(program_name)s-%(process_num)s
numprocs=1
autostart=true
autorestart=true
stopsignal=Term
boot-workers.sh
#!/bin/bash
set -eu
. venv/bin/activate
flask rq worker
Whenever I log in and launch boot-workers manually, everything works like a charm. With supervisord, it launches for a few seconds before exiting (with status 1) with the following error:
KeyError: <flask.cli.ScriptInfo object at 0x7f2c8ca77828>
Traceback (most recent call last):
File "/home/ceams_admin/ceams/venv/bin/flask", line 11, in <module>
sys.exit(main())
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 557, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/click/core.py", line 1132, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/click/core.py", line 1171, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 515, in get_command
rv = info.load_app().cli.get_command(ctx, name)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 377, in load_app
raise_if_not_found=False)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 254, in locate_app
return find_best_app(script_info, module)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 76, in find_best_app
app = call_factory(script_info, app_factory)
File "/home/ceams_admin/ceams/venv/lib/python3.6/site-packages/flask/cli.py", line 114, in call_factory
return app_factory(script_info)
File "/home/ceams_admin/ceams/app/__init__.py", line 29, in create_app
app.config.from_object(config[config_name])
It appears the virtual environment isn't being activated or something like that, though I'm not sure why. Has anyone successfully launched rq2 from supervisord? If so, can someone provide some debugging advice and/or an example? Thanks!
Hi I just want to ask for help how to run flask rq command in shell. I installed the flask_cli and try to run it, it show No shch command "rq".
I use Flask-RQ2 with supervisord. The trick is to run the command from inside the venv like this:
[program:rq-app]
command=/path/to/venv/bin/flask rq worker my-app-queue