Best Python code snippet using localstack_python
step_function.py
Source:step_function.py
...15 """ Calculate aggregated cost of a StepFunction execution16 :param execution_arn: ARN if StepFunction execution17 :return cost of execution18 """19 history = self.get_execution_history(execution_arn)20 lambda_arns = self._extract_lambda_arns(history)21 logs = []22 for arn in lambda_arns:23 log_group_name = self._log_group_name_from_lambda_arn(arn)24 latest_log_stream = self._get_latest_log_stream(log_group_name)25 if not latest_log_stream:26 logger.info(f"Execution Log not found for {arn}")27 continue28 log_stream_name = latest_log_stream['logStreamName']29 logger.info(log_stream_name)30 events = self.logs_client.get_log_events(logGroupName=log_group_name, logStreamName=log_stream_name)[31 'events']32 if events:33 last_report = list(filter(lambda e: e['message'].startswith('REPORT'), events))[-1]34 if last_report:35 execution_log = extract_data_from_log(last_report['message'])36 logs.append(execution_log)37 for log in logs:38 logger.info(log.to_string())39 cost = sum(log.cost for log in logs)40 return cost41 def get_execution_history(self, execution_arn: str):42 """ Returns the history of a StepFunction execution43 :param execution_arn: ARN of StepFunction execution44 :return History of execution45 """46 return self.step_functions.get_execution_history(executionArn=execution_arn)47 def check_if_execution_finished(self, execution_arn: str):48 """ Check execution history to see if execution has finished49 :param execution_arn: ARN of StepFunction execution50 :return True if execution has finished, False if it has not finished51 """52 events = self.get_execution_history(execution_arn)['events']53 if len(events) > 0:54 last_event = events[-1]55 if last_event['type'] == 'ExecutionSucceeded':56 return True57 if last_event['type'] == 'ExecutionFailed':58 raise Exception("Execution failed")59 return False60 def get_duration(self, execution_arn: str):61 """ Returns the duration of an execution62 :param execution_arn: ARN of StepFunction execution63 :return duration of execution in seconds64 """65 description = self.step_functions.describe_execution(executionArn=execution_arn)66 start = description['startDate']...
diagnostics.py
Source:diagnostics.py
...16 data = {17 "setup": await client.get_diagnostic_data(),18 "server": entry.data[CONF_HUB],19 "execution_history": [20 repr(execution) for execution in await client.get_execution_history()21 ],22 }23 return data24async def async_get_device_diagnostics(25 hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry26) -> dict[str, Any]:27 """Return diagnostics for a device entry."""28 entry_data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]29 client = entry_data.coordinator.client30 device_url = min(device.identifiers)[1]31 data = {32 "device": {33 "controllable_name": device.hw_version,34 "firmware": device.sw_version,35 "device_url": obfuscate_id(device_url),36 "model": device.model,37 },38 "setup": await client.get_diagnostic_data(),39 "server": entry.data[CONF_HUB],40 "execution_history": [41 repr(execution)42 for execution in await client.get_execution_history()43 if any(command.device_url == device_url for command in execution.commands)44 ],45 }...
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!!