Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit c534178

Browse files
authored
Updates protos to the current main state (#51)
* Updates protos to the current `main` state Signed-off-by: Albert Callarisa <albert@diagrid.io> * Exlude all proto files from ruff Signed-off-by: Albert Callarisa <albert@diagrid.io> * Fix imports to use a single file including all protos Signed-off-by: Albert Callarisa <albert@diagrid.io> * lint Signed-off-by: Albert Callarisa <albert@diagrid.io> * chore: Use exposed class for `schedule_new_orchestration` instead of using protos Signed-off-by: Albert Callarisa <albert@diagrid.io> * `GetWorkItemsRequest` doesn't have concurrency attributes anymore Signed-off-by: Albert Callarisa <albert@diagrid.io> --------- Signed-off-by: Albert Callarisa <albert@diagrid.io>
1 parent d2770cd commit c534178

25 files changed

Lines changed: 976 additions & 1837 deletions

Makefile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,28 @@ coverage-all: coverage-clean
1717
install:
1818
python3 -m pip install .
1919

20+
DAPR_BRANCH ?= main
21+
PROTO_URL = https://raw.githubusercontent.com/dapr/durabletask-protobuf/refs/heads/$(DAPR_BRANCH)/protos
22+
2023
gen-proto:
21-
curl -o durabletask/internal/orchestrator_service.proto https://raw.githubusercontent.com/dapr/durabletask-protobuf/refs/heads/main/protos/orchestrator_service.proto
22-
curl -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/dapr/durabletask-protobuf/commits?path=protos/orchestrator_service.proto&sha=main&per_page=1" | jq -r '.[0].sha' > durabletask/internal/PROTO_SOURCE_COMMIT_HASH
24+
curl -o durabletask/internal/orchestrator_service.proto $(PROTO_URL)/orchestrator_service.proto
25+
curl -o durabletask/internal/orchestration.proto $(PROTO_URL)/orchestration.proto
26+
curl -o durabletask/internal/history_events.proto $(PROTO_URL)/history_events.proto
27+
curl -o durabletask/internal/orchestrator_actions.proto $(PROTO_URL)/orchestrator_actions.proto
28+
curl -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/dapr/durabletask-protobuf/commits?path=protos/orchestrator_service.proto&sha=$(DAPR_BRANCH)&per_page=1" | jq -r '.[0].sha' > durabletask/internal/PROTO_SOURCE_COMMIT_HASH
2329
# NOTE: remember to check/update pyproject.toml protobuf version to follow https://github.com/grpc/grpc/blob/v{{VERSION GRPC IO TOOL BELLOW}}/tools/distrib/python/grpcio_tools/setup.py
2430
pip install .[dev]
25-
python3 -m grpc_tools.protoc --proto_path=. --python_out=. --pyi_out=. --grpc_python_out=. ./durabletask/internal/orchestrator_service.proto
31+
# Rewrite bare inter-proto imports to full paths so protoc generates package-qualified Python imports
32+
perl -i -pe 's|import "([^/]+\.proto)"|import "durabletask/internal/$$1"|g' durabletask/internal/*.proto
33+
python3 -m grpc_tools.protoc \
34+
--proto_path=. \
35+
--python_out=. \
36+
--pyi_out=. \
37+
--grpc_python_out=. \
38+
durabletask/internal/orchestrator_service.proto \
39+
durabletask/internal/orchestration.proto \
40+
durabletask/internal/history_events.proto \
41+
durabletask/internal/orchestrator_actions.proto
2642
rm durabletask/internal/*.proto
2743

2844
.PHONY: init test-unit test-e2e coverage-clean coverage-all gen-proto install

durabletask/aio/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
from google.protobuf import wrappers_pb2
1111

1212
import durabletask.internal.helpers as helpers
13-
import durabletask.internal.orchestrator_service_pb2 as pb
1413
import durabletask.internal.orchestrator_service_pb2_grpc as stubs
14+
import durabletask.internal.protos as pb
1515
import durabletask.internal.shared as shared
1616
from durabletask import task
1717
from durabletask.aio.internal.grpc_interceptor import DefaultClientInterceptorImpl
1818
from durabletask.aio.internal.shared import ClientInterceptor, get_grpc_aio_channel
1919
from durabletask.client import (
20+
OrchestrationIdReusePolicy,
2021
OrchestrationState,
2122
OrchestrationStatus,
2223
TInput,
@@ -81,7 +82,7 @@ async def schedule_new_orchestration(
8182
input: Optional[TInput] = None,
8283
instance_id: Optional[str] = None,
8384
start_at: Optional[datetime] = None,
84-
reuse_id_policy: Optional[pb.OrchestrationIdReusePolicy] = None,
85+
reuse_id_policy: Optional[OrchestrationIdReusePolicy] = None,
8586
) -> str:
8687
name = orchestrator if isinstance(orchestrator, str) else task.get_name(orchestrator)
8788

@@ -93,7 +94,7 @@ async def schedule_new_orchestration(
9394
else None,
9495
scheduledStartTimestamp=helpers.new_timestamp(start_at) if start_at else None,
9596
version=helpers.get_string_value(None),
96-
orchestrationIdReusePolicy=reuse_id_policy,
97+
orchestrationIdReusePolicy=reuse_id_policy._to_pb() if reuse_id_policy else None,
9798
)
9899

99100
self._logger.info(f"Starting new '{name}' instance with ID = '{req.instanceId}'.")

durabletask/client.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from google.protobuf import wrappers_pb2
1313

1414
import durabletask.internal.helpers as helpers
15-
import durabletask.internal.orchestrator_service_pb2 as pb
1615
import durabletask.internal.orchestrator_service_pb2_grpc as stubs
16+
import durabletask.internal.protos as pb
1717
import durabletask.internal.shared as shared
1818
from durabletask import task
1919
from durabletask.internal.grpc_interceptor import DefaultClientInterceptorImpl
@@ -47,6 +47,28 @@ def __str__(self):
4747
return helpers.get_orchestration_status_str(self.value)
4848

4949

50+
class OrchestrationIdReuseAction(Enum):
51+
"""Action to take when scheduling an orchestration whose ID already exists."""
52+
53+
ERROR = pb.ERROR
54+
IGNORE = pb.IGNORE
55+
TERMINATE = pb.TERMINATE
56+
57+
58+
@dataclass
59+
class OrchestrationIdReusePolicy:
60+
"""Policy controlling what happens when a new orchestration is scheduled with an ID that already exists."""
61+
62+
action: OrchestrationIdReuseAction
63+
operation_status: list[OrchestrationStatus]
64+
65+
def _to_pb(self) -> pb.OrchestrationIdReusePolicy:
66+
return pb.OrchestrationIdReusePolicy(
67+
operationStatus=[s.value for s in self.operation_status],
68+
action=self.action.value,
69+
)
70+
71+
5072
@dataclass
5173
class OrchestrationState:
5274
instance_id: str
@@ -166,7 +188,7 @@ def schedule_new_orchestration(
166188
input: Optional[TInput] = None,
167189
instance_id: Optional[str] = None,
168190
start_at: Optional[datetime] = None,
169-
reuse_id_policy: Optional[pb.OrchestrationIdReusePolicy] = None,
191+
reuse_id_policy: Optional[OrchestrationIdReusePolicy] = None,
170192
) -> str:
171193
name = orchestrator if isinstance(orchestrator, str) else task.get_name(orchestrator)
172194

@@ -180,7 +202,7 @@ def schedule_new_orchestration(
180202
input=input_pb,
181203
scheduledStartTimestamp=helpers.new_timestamp(start_at) if start_at else None,
182204
version=wrappers_pb2.StringValue(value=""),
183-
orchestrationIdReusePolicy=reuse_id_policy,
205+
orchestrationIdReusePolicy=reuse_id_policy._to_pb() if reuse_id_policy else None,
184206
)
185207

186208
self._logger.info(f"Starting new '{name}' instance with ID = '{req.instanceId}'.")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
889781bbe90e6ec84ebe169978c4f2fd0df74ff0
1+
a70949377cd95e5af1003f0b5e29e3772dea0d9e

durabletask/internal/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from google.protobuf import timestamp_pb2, wrappers_pb2
99

10-
import durabletask.internal.orchestrator_service_pb2 as pb
10+
import durabletask.internal.protos as pb
1111

1212
# TODO: The new_xxx_event methods are only used by test code and should be moved elsewhere
1313

durabletask/internal/history_events_pb2.py

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)