Aborting custom script runs #10430
-
I'm trying to figure out how to terminate a custom script mid-run (via the GUI) under specified conditions. I've tried using "sys.exit()" and "raise SystemExit", but both just change the script status to "running" and then sit there forever. The only successful "method" I can find is to intentionally run a bad command to cause an error. Is there a cleaner way to abort a script mid-run? |
Beta Was this translation helpful? Give feedback.
Answered by
kkthxbye-code
Sep 21, 2022
Replies: 2 comments 6 replies
-
Just raise any exception. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
agreusel
-
```
if VirtualChassis.objects.filter(name=f'{site_lower}-core01').exists():
return
```
Simply return within your run function.
…Sent from my iPhone
On 21 Sep 2022, at 19:34, agreusel ***@***.***> wrote:
I've tried that. The relevant code is here:
try:
virtual_chassis = VirtualChassis.objects.get(name = f"{site_lower}-core01")
self.log_failure(f"Virtual Chassis {virtual_chassis} exists, aborting.")
raise NameError
except VirtualChassis.DoesNotExist:
pass
I know the try statement is working because I get the log_failure message. But the exception is not being raised, and the script eventually errors out in the next code block where I'm creating a new virtual chassis with the same name as an existing one. The exception I'm trying to raise never gets processed/logged.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just raise any exception.