backup.py

changeset 38
085a635f23f5
parent 34
9fce700d42de
child 45
aa2a95dc6093
--- a/backup.py	Sun Jan 21 17:36:03 2018 +0000
+++ b/backup.py	Sun Jan 21 17:45:55 2018 +0000
@@ -111,7 +111,7 @@
 
         self.config=config
         self.lastrun_when=None
-        self.lastrun_success=None
+        self.lastrun_errors=None
         self.borg_instance=None
         self.current_operation=None
         self.thread_log=None
@@ -210,25 +210,25 @@
 
         res=self.borg_instance.read_result()
 
-        success=True
+        errors=False
 
         logger.debug('Borg result: %s' % str(res))
 
-        if res==None:
-            success=False
+        if res is None:
+            errors=True
 
         logger.debug('Waiting for borg subprocess to terminate in result thread')
 
-        success=success and self.borg_instance.wait()
+        errors=errors or not self.borg_instance.wait()
 
-        logger.debug('Borg subprocess terminated (success: %s); terminating result listener thread' % str(success))
+        logger.debug('Borg subprocess terminated (errors: %s); terminating result listener thread' % str(errors))
 
         self.thread_log.join()
 
         with self.lock:
             if self.current_operation['operation']=='create':
                 self.lastrun_when=self.current_operation['when_monotonic']
-                self.lastrun_success=success
+                self.lastrun_errors=errors
             self.thread_res=None
             self.thread_log=None
             self.borg_instance=None
@@ -294,7 +294,7 @@
             except Exception as err:
                 logger.debug('Rescheduling after failure')
                 self.lastrun_when=time.monotonic()
-                self.lastrun_success=False
+                self.lastrun_errors=True
                 self.__schedule_unlocked()
                 raise err
 
@@ -369,7 +369,7 @@
                 return {'operation': 'create',
                         'detail': 'initial',
                         'when_monotonic': now+initial_interval}
-        elif not self.lastrun_success:
+        elif self.lastrun_errors:
             if self.retry_interval==0:
                 return None
             else:
@@ -381,7 +381,7 @@
                 return None
             else:
                 return {'operation': 'create',
-                        'detail': None,
+                        'detail': 'normal',
                         'when_monotonic': self.lastrun_when+self.backup_interval}
 
     def __schedule_unlocked(self):
@@ -413,20 +413,29 @@
 
     def __status_unlocked(self):
         callback=self.__status_update_callback
+
         if self.current_operation:
             status=self.current_operation
             status['type']='current'
-        elif self.scheduled_operation:
-            status=self.scheduled_operation
-            status['type']='scheduled'
+            # Errors should be set by listeners
         else:
-            status={'type': 'nothing'}
+            if self.scheduled_operation:
+                status=self.scheduled_operation
+                status['type']='scheduled'
+            else:
+                status={'type': 'nothing'}
 
-        status['name']=self.name
+            if self.lastrun_errors is not None:
+                status['errors']=self.lastrun_errors
+
+        if 'detail' not in status:
+            status['detail']='NONE'
 
         if 'errors' not in status:
             status['errors']=False
 
+        status['name']=self.name
+
         if 'when_monotonic' in status:
             status['when']=(status['when_monotonic']
                             -time.monotonic()+time.time())

mercurial