mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Clear webhook queue on script failure
This commit is contained in:
parent
3b3247592e
commit
e2eb7fdfb5
@ -14,6 +14,7 @@ from extras.choices import JobResultStatusChoices
|
|||||||
from extras.context_managers import change_logging
|
from extras.context_managers import change_logging
|
||||||
from extras.models import JobResult
|
from extras.models import JobResult
|
||||||
from extras.scripts import get_script
|
from extras.scripts import get_script
|
||||||
|
from extras.signals import clear_webhooks
|
||||||
from utilities.exceptions import AbortTransaction
|
from utilities.exceptions import AbortTransaction
|
||||||
from utilities.utils import NetBoxFakeRequest
|
from utilities.utils import NetBoxFakeRequest
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
except AbortTransaction:
|
except AbortTransaction:
|
||||||
script.log_info("Database changes have been reverted automatically.")
|
script.log_info("Database changes have been reverted automatically.")
|
||||||
|
clear_webhooks.send(request)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
stacktrace = traceback.format_exc()
|
stacktrace = traceback.format_exc()
|
||||||
script.log_failure(
|
script.log_failure(
|
||||||
@ -58,7 +59,7 @@ class Command(BaseCommand):
|
|||||||
script.log_info("Database changes have been reverted due to error.")
|
script.log_info("Database changes have been reverted due to error.")
|
||||||
logger.error(f"Exception raised during script execution: {e}")
|
logger.error(f"Exception raised during script execution: {e}")
|
||||||
job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
|
job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
|
||||||
|
clear_webhooks.send(request)
|
||||||
finally:
|
finally:
|
||||||
job_result.data = ScriptOutputSerializer(script).data
|
job_result.data = ScriptOutputSerializer(script).data
|
||||||
job_result.save()
|
job_result.save()
|
||||||
|
@ -17,6 +17,7 @@ from django.utils.functional import classproperty
|
|||||||
|
|
||||||
from extras.api.serializers import ScriptOutputSerializer
|
from extras.api.serializers import ScriptOutputSerializer
|
||||||
from extras.choices import JobResultStatusChoices, LogLevelChoices
|
from extras.choices import JobResultStatusChoices, LogLevelChoices
|
||||||
|
from extras.signals import clear_webhooks
|
||||||
from ipam.formfields import IPAddressFormField, IPNetworkFormField
|
from ipam.formfields import IPAddressFormField, IPNetworkFormField
|
||||||
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
|
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
|
||||||
from utilities.exceptions import AbortTransaction
|
from utilities.exceptions import AbortTransaction
|
||||||
@ -458,7 +459,7 @@ def run_script(data, request, commit=True, *args, **kwargs):
|
|||||||
|
|
||||||
except AbortTransaction:
|
except AbortTransaction:
|
||||||
script.log_info("Database changes have been reverted automatically.")
|
script.log_info("Database changes have been reverted automatically.")
|
||||||
|
clear_webhooks.send(request)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
stacktrace = traceback.format_exc()
|
stacktrace = traceback.format_exc()
|
||||||
script.log_failure(
|
script.log_failure(
|
||||||
@ -467,7 +468,7 @@ def run_script(data, request, commit=True, *args, **kwargs):
|
|||||||
script.log_info("Database changes have been reverted due to error.")
|
script.log_info("Database changes have been reverted due to error.")
|
||||||
logger.error(f"Exception raised during script execution: {e}")
|
logger.error(f"Exception raised during script execution: {e}")
|
||||||
job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
|
job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
|
||||||
|
clear_webhooks.send(request)
|
||||||
finally:
|
finally:
|
||||||
job_result.data = ScriptOutputSerializer(script).data
|
job_result.data = ScriptOutputSerializer(script).data
|
||||||
job_result.save()
|
job_result.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user