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 83afc954c8d782403d113b9e5dc3daa3eac65fb9..7707f3b5548a4772ee992ee0bfef1be2c894de36 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 f6559f9b692294b401244f7dc65eb47c203a8779..dbc403e04585e21f167410da25d8da99f938bd06 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):
         """