|
1 | 1 | import uuid
|
2 |
| -from typing import Any |
3 | 2 |
|
4 | 3 | import httpx
|
5 | 4 | import nexusrpc.handler
|
6 | 5 | import pytest
|
7 |
| -from nexusrpc.handler import SyncOperationHandler |
| 6 | +from nexusrpc.handler import sync_operation_handler |
| 7 | +from nexusrpc.handler._util import get_operation_factory |
8 | 8 |
|
9 | 9 | from temporalio.client import Client
|
10 | 10 | from temporalio.worker import Worker
|
@@ -33,22 +33,19 @@ def make_incrementer_user_service_definition_and_service_handler_classes(
|
33 | 33 | #
|
34 | 34 | # service handler
|
35 | 35 | #
|
36 |
| - def factory(self: Any) -> nexusrpc.handler.OperationHandler[int, int]: |
37 |
| - async def _increment_op( |
38 |
| - ctx: nexusrpc.handler.StartOperationContext, |
39 |
| - input: int, |
40 |
| - ) -> int: |
41 |
| - return input + 1 |
42 |
| - |
43 |
| - return SyncOperationHandler.from_callable(_increment_op) |
44 |
| - |
45 |
| - op_handler_factories = { |
46 |
| - # TODO(nexus-prerelease): check that name=name should be required here. Should the op factory |
47 |
| - # name not default to the name of the method attribute (i.e. key), as opposed to |
48 |
| - # the name of the method object (i.e. value.__name__)? |
49 |
| - name: nexusrpc.handler.operation_handler(name=name)(factory) |
50 |
| - for name in op_names |
51 |
| - } |
| 36 | + @sync_operation_handler |
| 37 | + async def _increment_op( |
| 38 | + self, |
| 39 | + ctx: nexusrpc.handler.StartOperationContext, |
| 40 | + input: int, |
| 41 | + ) -> int: |
| 42 | + return input + 1 |
| 43 | + |
| 44 | + op_handler_factories = {} |
| 45 | + for name in op_names: |
| 46 | + op_handler_factory, _ = get_operation_factory(_increment_op) |
| 47 | + assert op_handler_factory |
| 48 | + op_handler_factories[name] = op_handler_factory |
52 | 49 |
|
53 | 50 | handler_cls = nexusrpc.handler.service_handler(service=service_cls)(
|
54 | 51 | type("ServiceImpl", (), op_handler_factories)
|
|
0 commit comments