def __init__(self, build_graph, delegate_build_strategy, async_context=AsyncContext()): super().__init__(build_graph) self._delegate_build_strategy = delegate_build_strategy self._async_context = async_context
def __init__( self, build_graph: BuildGraph, delegate_build_strategy: BuildStrategy, async_context: AsyncContext = AsyncContext(), ) -> None: super().__init__(build_graph) self._delegate_build_strategy = delegate_build_strategy self._async_context = async_context
def _initialize_all_functions_containers(self) -> None: """ Create and run a container for each available lambda function """ LOG.info("Initializing the lambda functions containers.") def initialize_function_container(function: Function) -> None: function_config = self.local_lambda_runner.get_invoke_config(function) self.lambda_runtime.run(None, function_config, self._debug_context) try: async_context = AsyncContext() for function in self._function_provider.get_all(): async_context.add_async_task(initialize_function_container, function) async_context.run_async(default_executor=False) LOG.info("Containers Initialization is done.") except KeyboardInterrupt: LOG.debug("Ctrl+C was pressed. Aborting containers initialization") self._clean_running_containers_and_related_resources() raise except Exception as ex: LOG.error("Lambda functions containers initialization failed because of %s", ex) self._clean_running_containers_and_related_resources() raise ContainersInitializationException("Lambda functions containers initialization failed") from ex
def test_async_execution_will_return_expected_results(self, function_ref, params, expected): async_context = AsyncContext() if params: async_context.add_async_task(function_ref, params) else: async_context.add_async_task(function_ref) results = async_context.run_async() self.assertEqual(len(results), 1) self.assertEqual(results[0], expected)
def test_async_execution_will_raise_exception(self): async_context = AsyncContext() async_context.add_async_task(raises_exception) self.assertRaises(Exception, async_context.run_async)