Skip to content

Commit 7d5def4

Browse files
committed
better error handling
1 parent befd13f commit 7d5def4

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

app/app.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424

2525
# PostgreSQL connection
2626
import psycopg2
27-
conn = psycopg2.connect(database="test",
28-
user=dotcloud_env['DOTCLOUD_DB_SQL_LOGIN'],
29-
password=dotcloud_env['DOTCLOUD_DB_SQL_PASSWORD'],
30-
host=dotcloud_env['DOTCLOUD_DB_SQL_HOST'],
31-
port=int(dotcloud_env['DOTCLOUD_DB_SQL_PORT']))
32-
cur = conn.cursor()
27+
28+
try:
29+
conn = psycopg2.connect(database="test",
30+
user=dotcloud_env['DOTCLOUD_DB_SQL_LOGIN'],
31+
password=dotcloud_env['DOTCLOUD_DB_SQL_PASSWORD'],
32+
host=dotcloud_env['DOTCLOUD_DB_SQL_HOST'],
33+
port=int(dotcloud_env['DOTCLOUD_DB_SQL_PORT']))
34+
cur = conn.cursor()
35+
except Exception as e:
36+
print e
37+
exit(1)
3338

3439
@app.route("/")
3540
def hello():

app/postgresql.py

100644100755
+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from os import path
55
from time import sleep
66
from sys import stdout as out
7+
import sys
78

89
dotcloud_env_file_path = path.expanduser('~/environment.json')
910
if path.exists(dotcloud_env_file_path):
@@ -21,7 +22,8 @@
2122

2223
out.write("Creating the database...")
2324
out.flush()
24-
for i in xrange(1,30):
25+
i = 60
26+
while True:
2527
try:
2628
conn = psycopg2.connect(
2729
user=env['DOTCLOUD_DB_SQL_LOGIN'],
@@ -36,6 +38,9 @@
3638
out.flush()
3739
break
3840
except Exception as e:
41+
i -= 1
42+
if i <= 0 :
43+
sys.exit(1)
3944
sleep(1)
4045
out.write(".")
4146
out.flush()

0 commit comments

Comments
 (0)