Skip to content

Commit db28f3f

Browse files
committed
Align sandbox preview behavior with dotnet
1 parent fdf908a commit db28f3f

9 files changed

Lines changed: 81 additions & 223 deletions

File tree

durabletask-azuremanaged/durabletask/azuremanaged/preview/sandboxes/declarations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ def build_profile_sandbox_activity_declarations() -> list[pb.SandboxActivityDecl
153153
activity_names = resolve_activity_names(profile.activity_names)
154154

155155
for activity_name in activity_names:
156-
existing_profile = activity_owners.get(activity_name)
156+
activity_key = activity_name.casefold()
157+
existing_profile = activity_owners.get(activity_key)
157158
if existing_profile and existing_profile != profile.worker_profile_id:
158159
raise ValueError(
159160
f"Sandbox activity '{activity_name}' is assigned to both worker profile "
160161
f"'{existing_profile}' and '{profile.worker_profile_id}'.")
161-
activity_owners[activity_name] = profile.worker_profile_id
162+
activity_owners[activity_key] = profile.worker_profile_id
162163

163164
declarations.append(_build_sandbox_activity_declaration(
164165
activity_names=activity_names,

durabletask-azuremanaged/durabletask/azuremanaged/preview/sandboxes/worker.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ def _resolve_worker_profile_id() -> str:
202202

203203
def _resolve_token_credential() -> TokenCredential | None:
204204
authentication = os.getenv("DTS_AUTHENTICATION", "")
205-
if authentication.lower() != "managedidentity":
206-
return None
205+
if authentication.strip().lower() != "managedidentity":
206+
raise ValueError(
207+
"Sandbox worker requires DTS_AUTHENTICATION to be ManagedIdentity.")
207208

208209
client_id = os.getenv("DTS_UMI_CLIENT_ID", "")
209210
if not client_id.strip():
@@ -231,12 +232,16 @@ def _resolve_sandbox_provider() -> str:
231232

232233
def _resolve_max_concurrent_activities() -> int:
233234
value = os.getenv("DTS_SANDBOX_MAX_ACTIVITIES")
234-
max_concurrent_activities = (
235-
int(value)
236-
if value
237-
else DEFAULT_MAX_CONCURRENT_ACTIVITIES)
235+
if value is None:
236+
return DEFAULT_MAX_CONCURRENT_ACTIVITIES
237+
238+
try:
239+
max_concurrent_activities = int(value.strip())
240+
except ValueError as ex:
241+
raise ValueError(
242+
"DTS_SANDBOX_MAX_ACTIVITIES must be a positive integer when injected by DTS.") from ex
238243

239244
if max_concurrent_activities <= 0:
240245
raise ValueError(
241-
"Sandbox activity worker max concurrent activities must be greater than zero.")
246+
"DTS_SANDBOX_MAX_ACTIVITIES must be a positive integer when injected by DTS.")
242247
return max_concurrent_activities

examples/sandboxes/Containerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ RUN pip install --no-cache-dir /src /src/durabletask-azuremanaged azure-identity
1313
COPY examples/sandboxes/remote_worker.py /app/remote_worker.py
1414
COPY examples/sandboxes/activity_names.py /app/activity_names.py
1515

16-
EXPOSE 8080
1716
ENTRYPOINT ["python", "/app/remote_worker.py"]

examples/sandboxes/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ names with `options.add_activity(...)`. The declarer and remote worker both use
4949
The remote worker code cannot pass Durable Task Scheduler runtime settings to the SDK. In a
5050
sandbox, `SandboxWorker()` reads `DTS_ENDPOINT`,
5151
`DTS_TASK_HUB`, `DTS_WORKER_PROFILE_ID`, `DTS_SANDBOX_MAX_ACTIVITIES`,
52-
`DTS_SANDBOX_PROVIDER`, and `DTS_SANDBOX_ID` from environment variables injected by
53-
Durable Task Scheduler. The worker reports its registered activity names when it connects, and
54-
Durable Task Scheduler validates they match the declaration before advertising worker capacity.
52+
`DTS_SANDBOX_PROVIDER`, `DTS_AUTHENTICATION`, `DTS_UMI_CLIENT_ID`, and
53+
`DTS_SANDBOX_ID` from environment variables injected by Durable Task Scheduler.
54+
The worker requires `DTS_AUTHENTICATION=ManagedIdentity` and reports its
55+
registered activity names when it connects. Durable Task Scheduler validates
56+
they match the declaration before advertising worker capacity.
5557

5658
## Build the remote worker image
5759

examples/serverless/Containerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/serverless/README.md

Lines changed: 0 additions & 77 deletions
This file was deleted.

examples/serverless/main_app.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

examples/serverless/remote_worker.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)