Skip to content

Commit

Permalink
Merge pull request ansible#12701 from AlanCoding/no_more_schedules
Browse files Browse the repository at this point in the history
Make schedule teardown more reliable
  • Loading branch information
AlanCoding authored Aug 20, 2022
2 parents 2aa9923 + 4b8a56b commit 2357e24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 6 additions & 4 deletions awxkit/awxkit/api/pages/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class Schedule(HasCreate, base.Base):
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"""
"""
In every case, we start by disabling the schedule
to avoid cascading errors from a cleanup failure.
Then, if we are told to prevent_teardown of schedules, we keep them
"""
try:
self.patch(enabled=False)
if not config.prevent_teardown:
return self.delete()
else:
self.patch(enabled=False)
except (exc.NoContent, exc.NotFound, exc.Forbidden):
pass

Expand Down
5 changes: 1 addition & 4 deletions awxkit/awxkit/api/pages/unified_job_templates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from awxkit.api.resources import resources
from awxkit.utils import random_title, update_payload
from awxkit.api.mixins import HasStatus
from awxkit.config import config
from . import base
from . import page

Expand Down Expand Up @@ -53,9 +52,7 @@ def add_schedule(self, name='', description='', enabled=True, rrule=None, **kwar
return schedule

def silent_delete(self):
if hasattr(self, '_schedules_store') and config.prevent_teardown:
# when prevent_teardown is off, we rely on cascade deletes
# in this case, looping is needed to turn them off
if hasattr(self, '_schedules_store'):
for schedule in self._schedules_store:
schedule.silent_delete()
return super(UnifiedJobTemplate, self).silent_delete()
Expand Down

0 comments on commit 2357e24

Please sign in to comment.