actions: Sort actions before running them.
[matthijs/projects/backupninja.git] / src / lib / backupninja / action.py
index 3f57a188f7b9b6a2f171bbb7f4a34442110b2a6b..bb54d0a168f8b6985505ca658903b0c705a60baa 100644 (file)
@@ -21,6 +21,8 @@
 
 """ Running backup actions """
 
 
 """ Running backup actions """
 
+import logging as log
+
 from backupninja import config
 from backupninja import handlers
 
 from backupninja import config
 from backupninja import handlers
 
@@ -32,6 +34,7 @@ def run_all_actions(opts, global_config):
     global configuration.
     """
     actions = config.list_actions(opts)
     global configuration.
     """
     actions = config.list_actions(opts)
+    actions.sort()
 
     for action in actions:
         run_action(action, opts, global_config)
 
     for action in actions:
         run_action(action, opts, global_config)
@@ -53,9 +56,12 @@ def run_action(action, opts, global_config):
     # Create a handler for this action
     handler = handlers.create_handler(action_ty, action_config)
 
     # Create a handler for this action
     handler = handlers.create_handler(action_ty, action_config)
 
-    if handler:
-        # Run the handler
-        handler.run()
-        handler.finish()
     # Silently skip invalid handlers, create_handler will have
     # logged an error
     # Silently skip invalid handlers, create_handler will have
     # logged an error
+    if handler:
+        try:
+            # Run the handler
+            handler.run()
+            handler.finish()
+        except Exception, e:
+            log.error('Running action "%s" failed: %s', action, e)