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

因此,我构建了一个聊天应用程序并将其与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命令运行该程序。在网络中直接添加<div id="todo"> <b-card class="col-md-12 text-center"> <b-row> <b-col md="4"> <b-input v-model="firstName" placeholder="Firstname"></b-input> </b-col> <b-col md="4"> <b-input v-model="lastName" placeholder="Lastname"></b-input> </b-col> <b-col md="2"> <b-btn class="btn btn-success" @click="addUser">Add User</b-btn> </b-col> </b-row> </b-card> <table> <caption>Users</caption> <thead> <tr> <th>Index</th> <th>First name</th> <th>Last name</th> </tr> </thead> <tbody> <tr v-for="(u,index) in users" :key="index"> <td>{{u.uid}}</td> <td>{{u.firstname}}</td> <td>{{u.lastname}}</td> </tr> </tbody> </table> </div> <script> export default { name: "todo",data() { return { users: [{ id: **this.uid**,firstname: "John",lastname: "Doe" }],**uid**: 1,firstName: "",lastName: "" }; },methods: { addUser() { let newUser = { id: this.id + 1,firstname: this.firstName,lastname: this.lastName }; this.users.push(newUser); (this.firstName = ""),(this.lastName = ""); } } }; </script> 只会导致整个应用程序失败。

这是我当前的运行命令

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

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

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

shenjie63293713 回答:如何使用daphne在heroku.yml中运行pgBouncer

最简单的解决方案是创建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
本文链接:https://www.f2er.com/2679370.html

大家都在问