Bläddra i källkod

Merge pull request #9473 from kkthxbye-code/fix-9466

Fixes #9466 - Clear webhook queue on script failure
Jeremy Stretch 3 år sedan
förälder
incheckning
56f3aaf7c8
2 ändrade filer med 6 tillägg och 4 borttagningar
  1. 3 2
      netbox/extras/management/commands/runscript.py
  2. 3 2
      netbox/extras/scripts.py

+ 3 - 2
netbox/extras/management/commands/runscript.py

@@ -14,6 +14,7 @@ from extras.choices import JobResultStatusChoices
 from extras.context_managers import change_logging
 from extras.models import JobResult
 from extras.scripts import get_script
+from extras.signals import clear_webhooks
 from utilities.exceptions import AbortTransaction
 from utilities.utils import NetBoxFakeRequest
 
@@ -49,7 +50,7 @@ class Command(BaseCommand):
 
             except AbortTransaction:
                 script.log_info("Database changes have been reverted automatically.")
-
+                clear_webhooks.send(request)
             except Exception as e:
                 stacktrace = traceback.format_exc()
                 script.log_failure(
@@ -58,7 +59,7 @@ class Command(BaseCommand):
                 script.log_info("Database changes have been reverted due to error.")
                 logger.error(f"Exception raised during script execution: {e}")
                 job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
-
+                clear_webhooks.send(request)
             finally:
                 job_result.data = ScriptOutputSerializer(script).data
                 job_result.save()

+ 3 - 2
netbox/extras/scripts.py

@@ -17,6 +17,7 @@ from django.utils.functional import classproperty
 
 from extras.api.serializers import ScriptOutputSerializer
 from extras.choices import JobResultStatusChoices, LogLevelChoices
+from extras.signals import clear_webhooks
 from ipam.formfields import IPAddressFormField, IPNetworkFormField
 from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
 from utilities.exceptions import AbortTransaction
@@ -465,7 +466,7 @@ def run_script(data, request, commit=True, *args, **kwargs):
 
         except AbortTransaction:
             script.log_info("Database changes have been reverted automatically.")
-
+            clear_webhooks.send(request)
         except Exception as e:
             stacktrace = traceback.format_exc()
             script.log_failure(
@@ -474,7 +475,7 @@ def run_script(data, request, commit=True, *args, **kwargs):
             script.log_info("Database changes have been reverted due to error.")
             logger.error(f"Exception raised during script execution: {e}")
             job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
-
+            clear_webhooks.send(request)
         finally:
             job_result.data = ScriptOutputSerializer(script).data
             job_result.save()