forked from hclivess/Bismuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
38 lines (32 loc) · 1.13 KB
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import time, random
def commit(cursor, app_log):
"""Secure commit for slow nodes"""
while True:
try:
cursor.commit()
break
except Exception as e:
app_log.warning("Retrying database execute due to {} in {}".format(e, cursor))
time.sleep(random.random())
def execute(cursor, query, app_log):
"""Secure execute for slow nodes"""
while True:
try:
cursor.execute(query)
break
except Exception as e:
app_log.warning("Database query: {} {}".format(cursor, query))
app_log.warning("Database retry reason: {}".format(e))
time.sleep(random.random())
return cursor
def execute_param(cursor, query, param, app_log):
"""Secure execute w/ param for slow nodes"""
while True:
try:
cursor.execute(query, param, app_log)
break
except Exception as e:
app_log.warning("Database query: {} {} {}".format(cursor, query, param))
app_log.warning("Database retry reason: {}".format(e))
time.sleep(random.random())
return cursor