我已经在heroku上托管了一个应用程序运行得很好。然而,db是在EC2上运行的RDS数据库。
当我在本地查询数据库时,我没有任何问题。但是,在将应用程序推送到Heroku后,我发现了超时错误。
2015-11-18T06:04:16.098644+00:00 app[web.1]: [2015-11-18 06:04:16 +0000] [3] [DEBUG] 2 workers
2015-11-18T06:04:17.100133+00:00 app[web.1]: [2015-11-18 06:04:17 +0000] [3] [DEBUG] 2 workers
2015-11-18T06:04:17.519180+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/login" host=myapp.herokuapp.com request_id=4cfb2d94-e5b8-467e-9949-8887a69c14f5 fwd="71.215.85.126" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0
2015-11-18T06:04:18.101610+00:00 app[web.1]: [2015-11-18 06:04:18 +0000] [3] [DEBUG] 2 workers
2015-11-18T06:04:19.110720+00:00 app[web.1]: [2015-11-18 06:04:19 +0000] [3] [DEBUG] 2 workers
我环顾四周,大多数帖子都提到了大量查询,但是当我在本地运行这些查询时,他们会在一秒内回来,因为他们并不是那么大。
以下是/login
的代码。为了调试我添加了x = User.query.all()
以查看我是否可以执行基本查询,因为只有1个用户,但我仍然没有得到超时。
@app.route('/login', methods=['GET','POST'])
def login():
x = User.query.all()
for i in x:
print i
if request.method == "POST":
#get all of the form fields
searchword = request.form.get('search', '')
registeredEmail = request.form.get('emailInput', '')
registeredPassword = request.form.get('passwordInput', '')
x = User.query.filter_by(email=registeredEmail).first()
if searchword:
return redirect('/search/{}'.format(searchword))
if x and x.email and check_password_hash(x.password, registeredPassword):
error = "User Exists! {}".format(x.email)
if request.form.get('remember-me') == 'on':
login_user(x, remember=True)
else:
login_user(x)
return redirect(url_for('home'))
else:
error = "Username/Password combo does not match"
return render_template('login.html', error=error)
elif current_user.get_id():
return redirect(url_for('home'))
else:
return render_template('login.html', logged_in=current_user.is_authenticated)
我知道我可以使用Heroku提供的本机postgres数据库,但我应该可以毫无问题地运行它。