7c13904539e9 — Peter Sanchez 13 years ago
Added --fail-silently option to run_callbacks command
1 files changed, 18 insertions(+), 2 deletions(-)

M callback/management/commands/run_callbacks.py
M callback/management/commands/run_callbacks.py +18 -2
@@ 1,12 1,28 @@ 
+from optparse import OptionParser, make_option
 from django.conf import settings
 from django.core.management.base import BaseCommand
-from callback import callback_manager
+from callback import CallbackException, callback_manager
 from callback.models import CallbackMap
 
 
 class Command(BaseCommand):
     help = 'Process all pending callbacks'
 
+    option_list = BaseCommand.option_list  + (
+        make_option(
+            '--fail-silently',
+            dest='fail_silently',
+            action='store_true',
+            help='If callback fails, do not raise the exception',
+        ),
+    )
+
     def handle(self, *args, **kwargs):
+        fail_silently = kwargs.get('fail_silently', False)
         for callback in CallbackMap.objects.all_live_callbacks():
-            callback_manager.process_callback(callback)
+            try:
+                callback_manager.process_callback(callback)
+            except CallbackException:
+                if not fail_silently:
+                    raise
+                pass