-
Notifications
You must be signed in to change notification settings - Fork 179
Add Nexus system payload codec rewrite support #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tconley1428
wants to merge
19
commits into
main
Choose a base branch
from
encoding_code_gen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ad3ee78
Add Nexus system payload codec rewrite support
tconley1428 f934a82
Make Nexus system model generation repo-local
tconley1428 9d4ba78
Clarify Nexus generator fallback requirements
tconley1428 7960be5
Refine Nexus system payload rewriting
tconley1428 e052321
Use generated system nexus module directly
tconley1428 ccf4ef3
Typecheck generated nexus system models
tconley1428 629567c
Use neutral payload variable names
tconley1428 28ffda6
Move Python system nexus envelope handling into visitor
tconley1428 f1c9437
Rename Python temporal nexus payload visitors
tconley1428 2999e9d
Work on user API
tconley1428 46ca02c
Align system nexus signal-with-start workflow API
tconley1428 df0ee0e
Update Python system nexus generated model usage
tconley1428 6b2f561
Tighten Python system nexus payload conversion
tconley1428 9136695
Move API off of external handle
tconley1428 9826236
Use shared workflow request builder for system nexus
tconley1428 bca2b0f
Refine Python payload visitor typing
tconley1428 7aaff38
Refine Python system nexus request handling
tconley1428 1d35209
Tighten Python type-check exclusions
tconley1428 c9af135
Refine signal_with_start_workflow API
tconley1428 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| NEXUS_RPC_GEN_ENV_VAR = "TEMPORAL_NEXUS_RPC_GEN_DIR" | ||
| NEXUS_RPC_GEN_VERSION = "0.1.0-alpha.4" | ||
|
|
||
|
|
||
| def main() -> None: | ||
| repo_root = Path(__file__).resolve().parent.parent | ||
| # TODO: Remove the local .nexusrpc.yaml shim once the upstream API repo | ||
| # checks in the Nexus definition we can consume directly. | ||
| override_root = normalize_nexus_rpc_gen_root( | ||
| Path.cwd(), env_value=NEXUS_RPC_GEN_ENV_VAR | ||
| ) | ||
| input_schema = ( | ||
| repo_root | ||
| / "temporalio" | ||
| / "nexus" | ||
| / "system" | ||
| / "_workflow_service.nexusrpc.yaml" | ||
| ) | ||
| output_file = ( | ||
| repo_root / "temporalio" / "nexus" / "system" / "_workflow_service_generated.py" | ||
| ) | ||
|
|
||
| if not input_schema.is_file(): | ||
| raise RuntimeError(f"Expected Nexus schema at {input_schema}") | ||
|
|
||
| run_nexus_rpc_gen( | ||
| override_root=override_root, | ||
| output_file=output_file, | ||
| input_schema=input_schema, | ||
| ) | ||
| subprocess.run( | ||
| [ | ||
| "uv", | ||
| "run", | ||
| "ruff", | ||
| "check", | ||
| "--select", | ||
| "I", | ||
| "--fix", | ||
| str(output_file), | ||
| ], | ||
| cwd=repo_root, | ||
| check=True, | ||
| ) | ||
| subprocess.run( | ||
| [ | ||
| "uv", | ||
| "run", | ||
| "ruff", | ||
| "format", | ||
| str(output_file), | ||
| ], | ||
| cwd=repo_root, | ||
| check=True, | ||
| ) | ||
|
|
||
|
|
||
| def run_nexus_rpc_gen( | ||
| *, override_root: Path | None, output_file: Path, input_schema: Path | ||
| ) -> None: | ||
| common_args = [ | ||
| "--lang", | ||
| "py", | ||
| "--out-file", | ||
| str(output_file), | ||
| "--temporal-nexus-payload-codec-support", | ||
| str(input_schema), | ||
| ] | ||
| if override_root is None: | ||
| subprocess.run( | ||
| ["npx", "--yes", f"nexus-rpc-gen@{NEXUS_RPC_GEN_VERSION}", *common_args], | ||
| check=True, | ||
| ) | ||
| return | ||
|
|
||
| subprocess.run( | ||
| [ | ||
| "node", | ||
| "packages/nexus-rpc-gen/dist/index.js", | ||
| *common_args, | ||
| ], | ||
| cwd=override_root, | ||
| check=True, | ||
| ) | ||
|
|
||
|
|
||
| def normalize_nexus_rpc_gen_root(base_dir: Path, env_value: str) -> Path | None: | ||
| raw_root = env_get(env_value) | ||
| if raw_root is None: | ||
| return None | ||
| candidate = Path(raw_root) | ||
| if not candidate.is_absolute(): | ||
| candidate = base_dir / candidate | ||
| candidate = candidate.resolve() | ||
| if (candidate / "package.json").is_file() and (candidate / "packages").is_dir(): | ||
| return candidate | ||
| if (candidate / "src" / "package.json").is_file(): | ||
| return candidate / "src" | ||
| raise RuntimeError( | ||
| f"{NEXUS_RPC_GEN_ENV_VAR} must point to the nexus-rpc-gen repo root or its src directory" | ||
| ) | ||
|
|
||
|
|
||
| def env_get(name: str) -> str | None: | ||
| return os.environ.get(name) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| main() | ||
| except Exception as err: | ||
| print(f"Failed to generate Nexus system models: {err}", file=sys.stderr) | ||
| raise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Generated system Nexus service models. | ||
|
|
||
| This package contains code generated from Temporal's system Nexus schemas. | ||
| Higher-level ergonomic APIs may wrap these generated types. | ||
| """ | ||
|
|
||
| from collections.abc import Awaitable, Callable, Sequence | ||
|
|
||
| import temporalio.api.common.v1 | ||
| import temporalio.converter | ||
|
|
||
| from . import _workflow_service_generated as generated | ||
| from ._workflow_service_generated import __temporal_nexus_payload_rewriters__ | ||
|
|
||
| TemporalNexusPayloadRewriter = Callable[ | ||
| [ | ||
| temporalio.api.common.v1.Payload, | ||
| Callable[ | ||
| [Sequence[temporalio.api.common.v1.Payload]], | ||
| Awaitable[list[temporalio.api.common.v1.Payload]], | ||
| ], | ||
| bool, | ||
| ], | ||
| Awaitable[temporalio.api.common.v1.Payload], | ||
| ] | ||
|
|
||
| _SYSTEM_NEXUS_PAYLOAD_CONVERTER = temporalio.converter.default().payload_converter | ||
|
|
||
|
|
||
| def get_payload_rewriter( | ||
| service: str, | ||
| operation: str, | ||
| ) -> TemporalNexusPayloadRewriter | None: | ||
| """Return the generated nested-payload rewriter for a system Nexus operation.""" | ||
| return __temporal_nexus_payload_rewriters__.get((service, operation)) | ||
|
|
||
|
|
||
| def is_system_operation(service: str, operation: str) -> bool: | ||
| """Return whether a Nexus operation uses the generated system envelope.""" | ||
| return get_payload_rewriter(service, operation) is not None | ||
|
|
||
|
|
||
| def get_payload_converter() -> temporalio.converter.PayloadConverter: | ||
| """Return the fixed payload converter for system Nexus outer envelopes.""" | ||
| return _SYSTEM_NEXUS_PAYLOAD_CONVERTER | ||
|
|
||
|
|
||
| __all__ = ( | ||
| "generated", | ||
| "get_payload_converter", | ||
| "get_payload_rewriter", | ||
| "is_system_operation", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # TODO: Remove this local shim once the upstream API repo checks in the Nexus | ||
| # definition and the generator can consume it directly. | ||
| nexusrpc: 1.0.0 | ||
| services: | ||
| WorkflowService: | ||
| operations: | ||
| SignalWithStartWorkflowExecution: | ||
| input: | ||
| $ref: ../../bridge/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml#/components/schemas/SignalWithStartWorkflowExecutionRequest | ||
| output: | ||
| $ref: ../../bridge/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml#/components/schemas/SignalWithStartWorkflowExecutionResponse |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.