dex-python-sdk 1.9.0__tar.gz → 1.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/PKG-INFO +97 -1
  2. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/README.md +96 -0
  3. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/__init__.py +5 -1
  4. dex_python_sdk-1.10.0/dex/_credential_transport.py +142 -0
  5. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_grpc_errors.py +1 -0
  6. dex_python_sdk-1.10.0/dex/_pull_worker.py +597 -0
  7. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_worker_dispatcher.py +1 -0
  8. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/async_client.py +5 -2
  9. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/async_worker.py +90 -32
  10. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/client.py +7 -2
  11. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/client_options.py +7 -0
  12. dex_python_sdk-1.10.0/dex/credential.py +138 -0
  13. dex_python_sdk-1.10.0/dex/dexpb/dex_pb2.py +545 -0
  14. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/dexpb/dex_pb2.pyi +214 -137
  15. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/dexpb/dex_pb2_grpc.py +108 -78
  16. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/worker.py +111 -35
  17. dex_python_sdk-1.10.0/dex/worker_options.py +164 -0
  18. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/pyproject.toml +1 -1
  19. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/Cargo.lock +12 -0
  20. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/Cargo.toml +1 -0
  21. dex_python_sdk-1.9.0/dex/dexpb/dex_pb2.py +0 -545
  22. dex_python_sdk-1.9.0/dex/worker_options.py +0 -52
  23. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/LEGACY_NOTICES.md +0 -0
  24. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/LICENSE +0 -0
  25. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_async_value_hydrator.py +0 -0
  26. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_async_worker_dispatcher.py +0 -0
  27. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_async_worker_service.py +0 -0
  28. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_invocation_context.py +0 -0
  29. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_native.pyi +0 -0
  30. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_server_protocol.py +0 -0
  31. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_utils.py +0 -0
  32. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_value_hydrator.py +0 -0
  33. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_value_mapper.py +0 -0
  34. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/_worker_service.py +0 -0
  35. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/attribute.py +0 -0
  36. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/attribute_match.py +0 -0
  37. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/blob_cache.py +0 -0
  38. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/channel.py +0 -0
  39. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/codec.py +0 -0
  40. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/condition.py +0 -0
  41. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/context.py +0 -0
  42. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/dexpb/__init__.py +0 -0
  43. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/flow.py +0 -0
  44. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/flow_config.py +0 -0
  45. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/flow_info.py +0 -0
  46. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/flow_options.py +0 -0
  47. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/flow_result.py +0 -0
  48. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/py.typed +0 -0
  49. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/rpc_invoke_options.py +0 -0
  50. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/runtime_errors.py +0 -0
  51. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/step.py +0 -0
  52. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/step_execution.py +0 -0
  53. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/stream.py +0 -0
  54. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/subflow.py +0 -0
  55. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/timer.py +0 -0
  56. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/wait.py +0 -0
  57. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/dex/wait_options.py +0 -0
  58. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
  59. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
  60. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
  61. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
  62. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
  63. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
  64. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
  65. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
  66. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
  67. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
  68. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
  69. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
  70. {dex_python_sdk-1.9.0 → dex_python_sdk-1.10.0}/sdk-rust/crates/dex-blob-cache-python/src/lib.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dex-python-sdk
3
- Version: 1.9.0
3
+ Version: 1.10.0
4
4
  Requires-Dist: grpcio>=1.83.0
5
5
  Requires-Dist: grpcio-status>=1.83.0
6
6
  Requires-Dist: protobuf>=7.35.1
@@ -17,6 +17,102 @@ Project-URL: Repository, https://github.com/superdurable/dex
17
17
 
18
18
  # Dex SDK for Python
19
19
 
20
+ ## Authentication
21
+
22
+ When Dex authentication is enabled, pass a bearer credential to each Client and
23
+ Worker that connects to the server. FileCredential reads the token at construction,
24
+ checks its mtime and size at most once per second, and reloads it after rotation.
25
+ Whitespace around the token is removed. An unreadable or empty file fails calls
26
+ until it is restored; the SDK does not send an old token.
27
+
28
+ ```python
29
+ from dex import Client, ClientOptions, FileCredential, Worker, WorkerOptions
30
+
31
+ credential = FileCredential("/var/run/secrets/dex/token")
32
+ client = Client(registry, cache, ClientOptions(credential=credential))
33
+ worker = Worker(registry, cache, WorkerOptions(credential=credential))
34
+ ```
35
+
36
+ The same option works with AsyncClient and AsyncWorker. Worker credentials cover
37
+ startup synchronization, blob hydration, and pull WorkerTaskService streams. A
38
+ pull stream reads the token when it opens and again on every reconnect. For a
39
+ custom credential, implement Credential.token() to return the current token;
40
+ the method may be called concurrently, and an exception fails the call before
41
+ it contacts Dex. AsyncClient and AsyncWorker also accept an awaitable token.
42
+ Synchronous tokens run in an executor for async calls and on the calling thread
43
+ for sync calls. Async calls bound token lookup by the RPC deadline when set;
44
+ pull stream opens use a 30-second lookup budget. Sync token lookup must return
45
+ promptly. By default, no authorization metadata is sent. Dex uses plaintext
46
+ gRPC, so protect the network path that carries the token.
47
+
48
+ ## Pull mode
49
+
50
+ Set `WorkerOptions.pull` to run a `Worker` or `AsyncWorker` with outbound task
51
+ streams. The Worker connects to the Dex server through `server_address` and
52
+ does not open a listener. Advertise `worker.worker_target` through
53
+ `ClientOptions.worker_target`. A single Flow can override the Client default
54
+ with `StartFlowOptions(config_override=FlowConfig(worker_target=...))`; a
55
+ SubFlow can use `SubFlowOptions` with the same `FlowConfig` override.
56
+
57
+ ```python
58
+ import threading
59
+ from dex import Client, ClientOptions, PullWorkerOptions, Worker, WorkerOptions
60
+
61
+ worker = Worker(
62
+ registry,
63
+ cache,
64
+ WorkerOptions(
65
+ server_address="dex.example:8801",
66
+ pull=PullWorkerOptions(max_concurrent_tasks=8, idle_streams_per_queue=1),
67
+ ),
68
+ )
69
+ worker_thread = threading.Thread(target=worker.start)
70
+ worker_thread.start()
71
+ client = Client(
72
+ registry,
73
+ cache,
74
+ ClientOptions(server_address="dex.example:8801", worker_target=worker.worker_target),
75
+ )
76
+ try:
77
+ client.start_flow(flow, flow_id, input_value)
78
+ finally:
79
+ client.close()
80
+ worker.stop()
81
+ worker_thread.join()
82
+ ```
83
+
84
+ The Worker polls its sticky queue and every registered Flow type queue. Flow
85
+ type names must be unique within a Dex server. `max_concurrent_tasks` defaults
86
+ to the CPU count, and `idle_streams_per_queue` defaults to one. At capacity,
87
+ the Worker rejects an assignment so Dex can reassign it. Each stream runs one
88
+ task at a time; Step heartbeat and stream writes use the same stream. A Worker
89
+ may hold up to `(1 + number of Flow types) * (idle_streams_per_queue +
90
+ max_concurrent_tasks)` streams because busy streams are replaced with idle
91
+ streams and retained after tasks finish. Size these options for the server's
92
+ per-Worker stream cap (256 by default).
93
+
94
+ The generated `app_worker_id` uses the first nonempty `DEX_WORKER_INSTANCE`,
95
+ `POD_NAME`, `HOSTNAME`, or system hostname, plus eight random base32 characters.
96
+ An override must uniquely identify one Worker process and change after restart.
97
+ It must contain 1-63 ASCII letters, digits, dots, underscores, or hyphens and
98
+ must not equal a registered Flow type. Pull mode cannot configure a bind address
99
+ or an advertised address or headless target. Use `WorkerTarget(pull=True)` for
100
+ Client defaults or Flow overrides when the Worker target is not directly in
101
+ scope.
102
+
103
+ Pull streams reconnect after failures. A server-directed reconnect waits for
104
+ an active task to finish, then waits up to `stop_drain_timeout` for the server
105
+ to close the stream after the final frame. An idle stream reconnects
106
+ immediately. An older server without pull support produces one explicit error
107
+ log and is retried after one minute. `start()` reports startup
108
+ synchronization errors, while later stream errors are logged and retried.
109
+ `stop()` drains for at most
110
+ `stop_drain_timeout`, which defaults to 30 seconds. Afterward it requests
111
+ cancellation and waits for handlers to return. Synchronous handlers should
112
+ check `Context.is_cancellation_requested()` during long operations. Streams
113
+ that sent a final frame wait for server EOF until the remaining Stop drain
114
+ deadline before the channel closes.
115
+
20
116
  ## Flow state I/O
21
117
 
22
118
  Applications read and write Flow state through typed RPCs. Client and AsyncClient
@@ -1,6 +1,102 @@
1
1
 
2
2
  # Dex SDK for Python
3
3
 
4
+ ## Authentication
5
+
6
+ When Dex authentication is enabled, pass a bearer credential to each Client and
7
+ Worker that connects to the server. FileCredential reads the token at construction,
8
+ checks its mtime and size at most once per second, and reloads it after rotation.
9
+ Whitespace around the token is removed. An unreadable or empty file fails calls
10
+ until it is restored; the SDK does not send an old token.
11
+
12
+ ```python
13
+ from dex import Client, ClientOptions, FileCredential, Worker, WorkerOptions
14
+
15
+ credential = FileCredential("/var/run/secrets/dex/token")
16
+ client = Client(registry, cache, ClientOptions(credential=credential))
17
+ worker = Worker(registry, cache, WorkerOptions(credential=credential))
18
+ ```
19
+
20
+ The same option works with AsyncClient and AsyncWorker. Worker credentials cover
21
+ startup synchronization, blob hydration, and pull WorkerTaskService streams. A
22
+ pull stream reads the token when it opens and again on every reconnect. For a
23
+ custom credential, implement Credential.token() to return the current token;
24
+ the method may be called concurrently, and an exception fails the call before
25
+ it contacts Dex. AsyncClient and AsyncWorker also accept an awaitable token.
26
+ Synchronous tokens run in an executor for async calls and on the calling thread
27
+ for sync calls. Async calls bound token lookup by the RPC deadline when set;
28
+ pull stream opens use a 30-second lookup budget. Sync token lookup must return
29
+ promptly. By default, no authorization metadata is sent. Dex uses plaintext
30
+ gRPC, so protect the network path that carries the token.
31
+
32
+ ## Pull mode
33
+
34
+ Set `WorkerOptions.pull` to run a `Worker` or `AsyncWorker` with outbound task
35
+ streams. The Worker connects to the Dex server through `server_address` and
36
+ does not open a listener. Advertise `worker.worker_target` through
37
+ `ClientOptions.worker_target`. A single Flow can override the Client default
38
+ with `StartFlowOptions(config_override=FlowConfig(worker_target=...))`; a
39
+ SubFlow can use `SubFlowOptions` with the same `FlowConfig` override.
40
+
41
+ ```python
42
+ import threading
43
+ from dex import Client, ClientOptions, PullWorkerOptions, Worker, WorkerOptions
44
+
45
+ worker = Worker(
46
+ registry,
47
+ cache,
48
+ WorkerOptions(
49
+ server_address="dex.example:8801",
50
+ pull=PullWorkerOptions(max_concurrent_tasks=8, idle_streams_per_queue=1),
51
+ ),
52
+ )
53
+ worker_thread = threading.Thread(target=worker.start)
54
+ worker_thread.start()
55
+ client = Client(
56
+ registry,
57
+ cache,
58
+ ClientOptions(server_address="dex.example:8801", worker_target=worker.worker_target),
59
+ )
60
+ try:
61
+ client.start_flow(flow, flow_id, input_value)
62
+ finally:
63
+ client.close()
64
+ worker.stop()
65
+ worker_thread.join()
66
+ ```
67
+
68
+ The Worker polls its sticky queue and every registered Flow type queue. Flow
69
+ type names must be unique within a Dex server. `max_concurrent_tasks` defaults
70
+ to the CPU count, and `idle_streams_per_queue` defaults to one. At capacity,
71
+ the Worker rejects an assignment so Dex can reassign it. Each stream runs one
72
+ task at a time; Step heartbeat and stream writes use the same stream. A Worker
73
+ may hold up to `(1 + number of Flow types) * (idle_streams_per_queue +
74
+ max_concurrent_tasks)` streams because busy streams are replaced with idle
75
+ streams and retained after tasks finish. Size these options for the server's
76
+ per-Worker stream cap (256 by default).
77
+
78
+ The generated `app_worker_id` uses the first nonempty `DEX_WORKER_INSTANCE`,
79
+ `POD_NAME`, `HOSTNAME`, or system hostname, plus eight random base32 characters.
80
+ An override must uniquely identify one Worker process and change after restart.
81
+ It must contain 1-63 ASCII letters, digits, dots, underscores, or hyphens and
82
+ must not equal a registered Flow type. Pull mode cannot configure a bind address
83
+ or an advertised address or headless target. Use `WorkerTarget(pull=True)` for
84
+ Client defaults or Flow overrides when the Worker target is not directly in
85
+ scope.
86
+
87
+ Pull streams reconnect after failures. A server-directed reconnect waits for
88
+ an active task to finish, then waits up to `stop_drain_timeout` for the server
89
+ to close the stream after the final frame. An idle stream reconnects
90
+ immediately. An older server without pull support produces one explicit error
91
+ log and is retried after one minute. `start()` reports startup
92
+ synchronization errors, while later stream errors are logged and retried.
93
+ `stop()` drains for at most
94
+ `stop_drain_timeout`, which defaults to 30 seconds. Afterward it requests
95
+ cancellation and waits for handlers to return. Synchronous handlers should
96
+ check `Context.is_cancellation_requested()` during long operations. Streams
97
+ that sent a final frame wait for server EOF until the remaining Stop drain
98
+ deadline before the channel closes.
99
+
4
100
  ## Flow state I/O
5
101
 
6
102
  Applications read and write Flow state through typed RPCs. Client and AsyncClient
@@ -24,6 +24,7 @@ from dex.blob_cache import BlobCache, BlobCacheConfig, open_blob_cache
24
24
  from dex.channel import Channel, ChannelMap, ChannelMapLoad, ChannelMessage
25
25
  from dex.client import Client
26
26
  from dex.client_options import ClientOptions
27
+ from dex.credential import Credential, FileCredential
27
28
  from dex.codec import (
28
29
  BOOL,
29
30
  BYTES,
@@ -112,7 +113,7 @@ from dex.timer import Timer
112
113
  from dex.wait import Wait
113
114
  from dex.wait_options import WaitForAttributeOptions, WaitForStepCompletionOptions
114
115
  from dex.worker import Worker
115
- from dex.worker_options import WorkerOptions, WorkerTarget
116
+ from dex.worker_options import PullWorkerOptions, WorkerOptions, WorkerTarget
116
117
 
117
118
  __all__ = [
118
119
  "BOOL",
@@ -143,6 +144,7 @@ __all__ = [
143
144
  "ChannelMessagesNotLoadedError",
144
145
  "Client",
145
146
  "ClientOptions",
147
+ "Credential",
146
148
  "Codec",
147
149
  "CodecRegistry",
148
150
  "ConditionCombination",
@@ -150,6 +152,7 @@ __all__ = [
150
152
  "DexServiceError",
151
153
  "ErrorSubStatus",
152
154
  "Flow",
155
+ "FileCredential",
153
156
  "FlowAlreadyStartedError",
154
157
  "FlowConfig",
155
158
  "FlowDefinitionError",
@@ -210,6 +213,7 @@ __all__ = [
210
213
  "WorkerInvocationError",
211
214
  "WorkerOptions",
212
215
  "WorkerTarget",
216
+ "PullWorkerOptions",
213
217
  "WaitForAttributeOptions",
214
218
  "WaitForStepCompletionOptions",
215
219
  "dead_end",
@@ -0,0 +1,142 @@
1
+ # Copyright (c) 2026 Super Durable, Inc.
2
+ #
3
+ # Licensed under the Sustainable Use License 1.0.
4
+ # You may not use this file except in compliance with the License.
5
+ # See the LICENSE file in the repository root.
6
+ #
7
+ # SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
+
9
+ """Attach bearer metadata to outbound gRPC calls."""
10
+
11
+ # mypy: disable-error-code=type-arg
12
+
13
+ from __future__ import annotations
14
+
15
+ import asyncio
16
+ import inspect
17
+ from collections.abc import Callable
18
+ from typing import Any, NamedTuple, cast
19
+
20
+ import grpc
21
+
22
+ from dex.credential import Credential
23
+
24
+
25
+ class _SyncCallDetails(NamedTuple):
26
+ method: str
27
+ timeout: float | None
28
+ metadata: Any
29
+ credentials: grpc.CallCredentials | None
30
+ wait_for_ready: bool | None
31
+ compression: grpc.Compression | None
32
+
33
+
34
+ def credential_metadata(credential: Credential | None, metadata: Any = None) -> Any:
35
+ if credential is None:
36
+ return metadata
37
+ token = credential.token()
38
+ if inspect.isawaitable(token):
39
+ if inspect.iscoroutine(token):
40
+ token.close()
41
+ raise TypeError("synchronous calls require a synchronous credential")
42
+ return tuple(metadata or ()) + (("authorization", "Bearer " + token),)
43
+
44
+
45
+ async def async_credential_metadata(
46
+ credential: Credential, metadata: Any = None, timeout: float | None = None
47
+ ) -> Any:
48
+ try:
49
+ token = await asyncio.wait_for(
50
+ _resolve_async_token(credential), timeout=timeout
51
+ )
52
+ except TimeoutError as error:
53
+ raise credential_deadline_error() from error
54
+ return tuple(metadata or ()) + (("authorization", "Bearer " + token),)
55
+
56
+
57
+ async def _resolve_async_token(credential: Credential) -> str:
58
+ token = await asyncio.to_thread(credential.token)
59
+ if inspect.isawaitable(token):
60
+ return await token
61
+ return token
62
+
63
+
64
+ def credential_deadline_error() -> grpc.aio.AioRpcError:
65
+ return grpc.aio.AioRpcError(
66
+ grpc.StatusCode.DEADLINE_EXCEEDED,
67
+ grpc.aio.Metadata(),
68
+ grpc.aio.Metadata(),
69
+ "credential lookup exceeded RPC deadline",
70
+ None,
71
+ )
72
+
73
+
74
+ class _SyncCredentialInterceptor(grpc.UnaryUnaryClientInterceptor):
75
+ def __init__(self, credential: Credential) -> None:
76
+ self._credential = credential
77
+
78
+ def intercept_unary_unary(
79
+ self,
80
+ continuation: Callable[..., Any],
81
+ client_call_details: grpc.ClientCallDetails,
82
+ request: Any,
83
+ ) -> Any:
84
+ details = _SyncCallDetails(
85
+ client_call_details.method,
86
+ client_call_details.timeout,
87
+ credential_metadata(self._credential, client_call_details.metadata),
88
+ client_call_details.credentials,
89
+ client_call_details.wait_for_ready,
90
+ client_call_details.compression,
91
+ )
92
+ return continuation(details, request)
93
+
94
+
95
+ class _AsyncCredentialInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
96
+ def __init__(self, credential: Credential) -> None:
97
+ self._credential = credential
98
+
99
+ async def intercept_unary_unary(
100
+ self,
101
+ continuation: Callable[..., Any],
102
+ client_call_details: grpc.aio.ClientCallDetails,
103
+ request: Any,
104
+ ) -> Any:
105
+ loop = asyncio.get_running_loop()
106
+ started_at = loop.time()
107
+ metadata = await async_credential_metadata(
108
+ self._credential, client_call_details.metadata, client_call_details.timeout
109
+ )
110
+ remaining_timeout = client_call_details.timeout
111
+ if remaining_timeout is not None:
112
+ remaining_timeout -= loop.time() - started_at
113
+ if remaining_timeout <= 0:
114
+ raise credential_deadline_error()
115
+ details = grpc.aio.ClientCallDetails(
116
+ client_call_details.method,
117
+ remaining_timeout,
118
+ metadata,
119
+ client_call_details.credentials,
120
+ client_call_details.wait_for_ready,
121
+ )
122
+ return await continuation(details, request)
123
+
124
+
125
+ def sync_channel(server_address: str, credential: Credential | None) -> grpc.Channel:
126
+ channel = grpc.insecure_channel(server_address)
127
+ if credential is None:
128
+ return channel
129
+ return grpc.intercept_channel(channel, _SyncCredentialInterceptor(credential))
130
+
131
+
132
+ def async_channel(
133
+ server_address: str, credential: Credential | None
134
+ ) -> grpc.aio.Channel:
135
+ if credential is None:
136
+ return grpc.aio.insecure_channel(server_address)
137
+ return grpc.aio.insecure_channel(
138
+ server_address,
139
+ interceptors=[
140
+ cast(grpc.aio.ClientInterceptor, _AsyncCredentialInterceptor(credential))
141
+ ],
142
+ )
@@ -200,6 +200,7 @@ def _worker_error_status(error: BaseException) -> status_pb2.Status:
200
200
  _ERROR_TYPE_TRUNCATION_MARKER,
201
201
  ),
202
202
  stack_trace=_worker_stack_trace(stack_trace_source),
203
+ grpc_status=grpc.StatusCode.UNKNOWN.value[0],
203
204
  )
204
205
  if retry_after_error is not None:
205
206
  worker_error.retry_after_seconds = retry_after_error.after_seconds