action: Let each action track a status and log it.
authorMatthijs Kooijman <matthijs@stdin.nl>
Sat, 7 Aug 2010 18:38:25 +0000 (20:38 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Sat, 7 Aug 2010 18:38:25 +0000 (20:38 +0200)
This allows (in the future) for a nice summary after each run and allows
actions to fail without breaking out with an exception right away.

src/lib/backupninja/action.py
src/lib/backupninja/handlers/__init__.py

index 83afc95..7707f3b 100644 (file)
@@ -68,7 +68,15 @@ def run_action(action_config, opts, global_config):
         # Run it
         action.run(test=opts.test)
         action.finish(test=opts.test)
+        # Ask the action if there where any failures
+        success = not action.failed
     except Exception, e:
-        log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e)
+        log.error('Unexpected exception: %s', e)
         import traceback
         log.debug(traceback.format_exc())
+        success = False
+
+    if success:
+        log.info('Running action "%s.%s" succeeded', action_name, action_ty)
+    else:
+        log.info('Running action "%s.%s" failed', action_name, action_ty)
index f6559f9..dbc403e 100644 (file)
@@ -38,6 +38,9 @@ class Action(object):
         # See backupninja.config.load_config for the structure of this
         # value.
         self.default_config = {}
+        # Assume we'll run succesfully. If anything fails in the
+        # meanwhile, set this to True.
+        self.failed = False
 
     def run(self, **kwargs):
         """