in cdk-project/lambda/python-functions/clean_endpoints.py [0:0]
def stop_resources(client, resource_names, resource_type):
stopped_all_resources = True
for resource_name in resource_names:
logger.info("Stopping %s", resource_name)
if resource_type == "MonitoringSchedules":
try:
client.stop_monitoring_schedule(MonitoringScheduleName=resource_name)
except Exception: # pylint: disable=broad-except
logger.exception("Unable to stop monitoring schedule")
stopped_all_resources = False
for _ in retries(60, "Waiting for Monitoring Schedules to stop", seconds_to_sleep=5):
status = client.describe_monitoring_schedule(MonitoringScheduleName=resource_name)[
"MonitoringScheduleStatus"
]
if status in {"Stopped", "Failed", "Completed"}:
break
if resource_type == "ProcessingJobs":
try:
client.stop_processing_job(ProcessingJobName=resource_name)
except Exception: # pylint: disable=broad-except
logger.exception("Unable to stop processing job")
stopped_all_resources = False
for _ in retries(60, "Waiting for Processing Jobs to stop", seconds_to_sleep=5):
status = client.describe_processing_job(ProcessingJobName=resource_name)[
"ProcessingJobStatus"
]
if status in {"Stopped", "Failed", "Completed"}:
break
logger.info("Stopped %s", resource_name)
time.sleep(0.5)
return stopped_all_resources