使用超级用户运行flask-rq2

时间:2019-04-19 20:33:19

标签: python linux flask redis supervisord

我有一个不错的Flask应用程序,该应用程序使用flask-rq2来运行后台任务-一切都在本地运行良好,但是当我尝试投入生产时遇到了麻烦。一切都在Ubuntu 18.04服务器上的虚拟环境中运行,我正在使用gunicorn运行Flask应用程序,并使用supervisor进行管理。 Flask应用程序运行正常,但RQ工作人员启动并快速失败,并出现以下错误,使我似乎不在虚拟环境中。

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])

我尝试通过几种不同的方式为主管设置配置文件,但目前已确定以下内容:

rq.conf

[program:rq]
directory=/home/ceams_admin/ceams
command=sh boot-workers.sh
process_name=%(program_name)s-%(process_num)s
numprocs=1
autostart=true
autorestart=true
stopsignal=TERM
stdout_logfile=/var/log/redis/redis_stdout.log
stderr_logfile=/var/log/redis/redis_stderr.log
stderr_logfile_maxbytes=10MB
stdout_logfile_maxbytes=10MB

其中boot-workers.sh是:

#!/bin/bash
set -eu

. venv/bin/activate
flask rq worker

关于如何更好地调试或如何启动rq的任何建议都很棒!

0 个答案:

没有答案