async def publish(self, obj: Any, **kwargs): """ Publishes given event. :param obj: event object :param kwargs: event extra arguments """ await self._scheduler.schedule( ActionSubject(subject=obj, inject=kwargs))
async def execute(self, obj: Any, **kwargs): """ Executes given request. :param obj: request object :param kwargs: request extra arguments :raises LookupHandlerStoreError: when there is no matching handler to process given request :return: request processing result """ result = await self._executor(ActionSubject(subject=obj, inject=kwargs)) assert isinstance( result, ActionResult ), "modifier or handler should provide `ActionResult` type object" return result.result
async def test_direct_handler_create_successful( obj, sig, name: Optional[str], arg_map: Dict[str, str], expected_result, ): get_details = CallableObjDetails() arg_get = HandlerSubjectArgGet(name=name) handler_create = CallableHandlerCreate( subject_as_keyword=name is not None, arg_map=arg_map, arg_strict=True, ) details = get_details(sig) arg = arg_get(details) details.obj = obj handler = handler_create(details, arg, obj) result = await handler(ActionSubject(subject="test", inject={"x": 1, "y": 2})) assert isinstance(result, ActionResult) assert result.result == expected_result
async def _check_handler_works(handler: Handler): result = await handler(ActionSubject(subject="test", inject={})) assert result.result == "test"
def action(): return ActionSubject(subject="test", inject={"a": 10, "b": 20})
def create_action(): return ActionSubject("test", inject={})
def action(): return ActionSubject(subject="test", inject={})
async def _op(action: ActionSubject): if "seq" not in action.inject: action.inject["seq"] = [] seq = action.inject["seq"] seq.append(seq_item) return await call(action)
async def _check_handler(handler: Handler): action = ActionSubject(subject="test", inject={"x": 1, "y": 2}) result: ActionResult = await handler(action) assert result.result == ("test", 1, 2)