Allow preserving schedules with prevent_teardown

This commit is contained in:
AlanCoding
2020-02-10 15:33:16 -05:00
committed by Alan Rominger
parent d834519aae
commit 51f4a40cd4
2 changed files with 30 additions and 1 deletions

View File

@@ -2,7 +2,9 @@ from contextlib import suppress
from awxkit.api.pages import UnifiedJob
from awxkit.api.resources import resources
from awxkit.config import config
import awxkit.exceptions as exc
from . import page
from . import base
@@ -11,6 +13,17 @@ class Schedule(UnifiedJob):
NATURAL_KEY = ('unified_job_template', 'name')
def silent_delete(self):
"""If we are told to prevent_teardown of schedules, then keep them
but do not leave them activated, or system will be swamped quickly"""
try:
if not config.prevent_teardown:
return self.delete()
else:
self.patch(enabled=False)
except (exc.NoContent, exc.NotFound, exc.Forbidden):
pass
page.register_page([resources.schedule, resources.related_schedule], Schedule)