[PATCH 5/5] If we loop, exit the account synchronization after 3 failed attempts

Sebastian Spaeth Sebastian at SSpaeth.de
Wed May 4 15:45:28 BST 2011


This should get rid of intermittent network failures, but lets us bail
out on permanent errors.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/accounts.py |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index f8e0d81..40bf1d4 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -184,8 +184,8 @@ class SyncableAccount(Account):
         self.localrepos  = Repository(self, 'local')
         self.statusrepos = Repository(self, 'status')
 
-        # Loop account synchronization if needed
-        looping = True
+        # Loop account sync if needed (bail out after 3 failures)
+        looping = 3
         while looping:
             try:
                 try:
@@ -196,16 +196,20 @@ class SyncableAccount(Account):
                     self.ui.warn(e.reason)
                     #stop looping and bubble up Exception if needed
                     if e.severity >= OfflineImapError.ERROR.REPO:
-                        looping = 0
-                        if e.severity > OfflineImapError.ERROR.REPO:
+                        if looping: 
+                            looping -= 1
+                        if e.severity >= OfflineImapError.ERROR.CRITICAL:
                             raise
                 except:
                     self.ui.warn("Error occured attempting to sync "\
                                  "account '%s':\n"% (self, traceback.format_exc()))
+                else:
+                    # after success sync, reset the looping counter to 3
+                    if self.refreshperiod:
+                        looping = 3
             finally:
-                looping = looping and \
-                    self.refreshperiod and \
-                    self.sleeper(siglistener) != 2
+                if self.sleeper(siglistener) >= 2:
+                    looping = 0                    
                 self.ui.acctdone(self.name)
 
 
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list