@@ -17,7 +17,7 @@ class MongoConnection:
1717 A concrete class that defines a MongoDB client
1818 """
1919
20- MAX_AUTO_RECONNECT_ATTEMPTS = 5
20+ MAX_AUTO_RECONNECT_ATTEMPTS = 10
2121
2222 def __init__ (self ):
2323 # Needed to run tests in test_ingest.py in CircleCI.
@@ -52,12 +52,11 @@ def graceful_auto_reconnect(mongo_op_func):
5252 import random
5353 import math
5454
55- MAX_ATTEMPTS = 5
5655 # Adopted from https://stackoverflow.com/questions/46939285
5756
5857 def retry (attempt_num ):
59- if attempt_num < MAX_ATTEMPTS - 1 :
60- exp_backoff = pow (2 , attempt_num )
58+ if attempt_num < MongoConnection . MAX_AUTO_RECONNECT_ATTEMPTS - 1 :
59+ exp_backoff = pow (2 , attempt_num + 1 )
6160 max_jitter = math .ceil (exp_backoff * 0.2 )
6261 final_wait_time = exp_backoff + random .randint (
6362 0 , max_jitter
@@ -68,17 +67,17 @@ def retry(attempt_num):
6867 @functools .wraps (mongo_op_func )
6968 def wrapper (* args , ** kwargs ):
7069 args = list (args )
71- for attempt in range (MAX_ATTEMPTS ):
70+ for attempt in range (MongoConnection . MAX_AUTO_RECONNECT_ATTEMPTS ):
7271 try :
7372 return mongo_op_func (* args , ** kwargs )
7473 except AutoReconnect as e :
75- if attempt < MAX_ATTEMPTS - 1 :
74+ if attempt < MongoConnection . MAX_AUTO_RECONNECT_ATTEMPTS - 1 :
7675 dev_logger .warning ("PyMongo auto-reconnecting... %s." , str (e ))
7776 retry (attempt )
7877 else :
7978 raise e
8079 except BulkWriteError as bwe :
81- if attempt < MAX_ATTEMPTS - 1 :
80+ if attempt < MongoConnection . MAX_AUTO_RECONNECT_ATTEMPTS - 1 :
8281 dev_logger .warning (
8382 "Batch ops error occurred. Reinsert attempt %s." , str (attempt )
8483 )
0 commit comments