如何使用daphne在heroku.yml中运行pgBouncer

问题描述 投票:0回答:1

因此,我构建了一个聊天应用程序并将其与heroku一起部署。由于我在hobby-dev上,所以我只能与Postgres建立20条连接,因此在网上提出一些建议后,我决定使用pgbouncer可能是个好主意。关于设置构建包的heroku文档(例如https://devcenter.heroku.com/articles/python-concurrency-and-database-connections#number-of-active-connections的最后一部分)是受限制的,我发现的所有内容都要求我更改Procfile中的某些内容。问题是我使用的是docker容器,因此最终使用heroku.yml和daphne命令运行该程序。在Web中直接添加bin/start-pgbouncer只会导致整个应用程序失败。

这是我当前的运行命令

run:
  web: daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2

我尝试过

run:
  web: bin/start-pgbouncer-stunnel daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2

run:
  web: start-pgbouncer-stunnel daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2

均失败。我还在heroku日志中发现heroku似乎自动将/bin/sh -c附加到我的运行命令中(例如/bin/sh -c daphne\ test_project.asgi:application\ --port\ \53166\ --bind\ 0.0.0.0\ -v2)。

这可能引起问题吗?我应该在网络中放置什么以与我的应用程序一起运行pg-bouncer?

docker heroku pgbouncer daphne
1个回答
0
投票

最简单的解决方案是创建bash脚本run.sh

set -ev

service pgbouncer start
daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2
service pgbouncer stop

run:
  web: run.sh
© www.soinside.com 2019 - 2024. All rights reserved.