Best Python code snippet using localstack_python
alarm_scheduler.py
Source:alarm_scheduler.py
...45 def schedule_metric_alarm(self, alarm_arn: str) -> None:46 """(Re-)schedules the alarm, if the alarm is re-scheduled, the running alarm scheduler will be cancelled before47 starting a new one"""48 alarm_details = get_metric_alarm_details_for_alarm_arn(alarm_arn)49 self.delete_scheduler_for_alarm(alarm_arn)50 if not self._is_alarm_supported(alarm_details):51 LOG.warning(52 "Given alarm configuration not yet supported, alarm state will not be evaluated."53 )54 return55 period = alarm_details["Period"]56 evaluation_periods = alarm_details["EvaluationPeriods"]57 schedule_period = evaluation_periods * period58 def on_error(e):59 LOG.exception("Error executing scheduled alarm", exc_info=e)60 task = self.scheduler.schedule(61 func=calculate_alarm_state,62 period=schedule_period,63 fixed_rate=True,64 args=[alarm_arn],65 on_error=on_error,66 )67 self.scheduled_alarms[alarm_arn] = task68 def delete_scheduler_for_alarm(self, alarm_arn: str) -> None:69 """70 Deletes the recurring scheduler for an alarm71 :param alarm_arn: the arn of the alarm to be removed72 """73 task = self.scheduled_alarms.pop(alarm_arn, None)74 if task:75 task.cancel()76 def restart_existing_alarms(self) -> None:77 """78 Only used re-create persistent state. Reschedules alarms that already exist79 """80 service = "cloudwatch"81 for region in aws_stack.get_valid_regions_for_service(service):82 client = aws_stack.connect_to_service(service, region_name=region)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!