Skip to content

Commit 1da819e

Browse files
committed
Fixing grpc calls
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
1 parent 33c8b11 commit 1da819e

File tree

3 files changed

+67
-68
lines changed

3 files changed

+67
-68
lines changed

durabletask/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def __init__(self, *,
113113

114114
channel = shared.get_grpc_channel(
115115
host_address=host_address,
116-
metadata=metadata,
117116
secure_channel=secure_channel,
118117
interceptors=self._interceptors
119118
)

durabletask/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def add_activity(self, fn: task.Activity) -> str:
131131

132132
def start(self):
133133
"""Starts the worker on a background thread and begins listening for work items."""
134-
channel = shared.get_grpc_channel(self._host_address, self._metadata, self._secure_channel, self._interceptors)
134+
channel = shared.get_grpc_channel(self._host_address, self._secure_channel, self._interceptors)
135135
stub = stubs.TaskHubSidecarServiceStub(channel)
136136

137137
if self._is_running:
Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
"""End-to-end sample that demonstrates how to configure an orchestrator
2-
that calls an activity function in a sequence and prints the outputs."""
3-
import os
4-
from durabletask import task
5-
from durabletask.azuremanaged.worker import DurableTaskSchedulerWorker
6-
from durabletask.azuremanaged.client import DurableTaskSchedulerClient, OrchestrationStatus
7-
from azure.identity import DefaultAzureCredential
8-
9-
def hello(ctx: task.ActivityContext, name: str) -> str:
10-
"""Activity function that returns a greeting"""
11-
return f'Hello {name}!'
12-
13-
14-
def sequence(ctx: task.OrchestrationContext, _):
15-
"""Orchestrator function that calls the 'hello' activity function in a sequence"""
16-
# call "hello" activity function in a sequence
17-
result1 = yield ctx.call_activity(hello, input='Tokyo')
18-
result2 = yield ctx.call_activity(hello, input='Seattle')
19-
result3 = yield ctx.call_activity(hello, input='London')
20-
21-
# return an array of results
22-
return [result1, result2, result3]
23-
24-
25-
# Read the environment variable
26-
taskhub_name = os.getenv("TASKHUB")
27-
28-
# Check if the variable exists
29-
if taskhub_name:
30-
print(f"The value of TASKHUB is: {taskhub_name}")
31-
else:
32-
print("TASKHUB is not set. Please set the TASKHUB environment variable to the name of the taskhub you wish to use")
33-
print("If you are using windows powershell, run the following: $env:TASKHUB=\"<taskhubname>\"")
34-
print("If you are using bash, run the following: export TASKHUB=\"<taskhubname>\"")
35-
exit()
36-
37-
# Read the environment variable
38-
endpoint = os.getenv("ENDPOINT")
39-
40-
# Check if the variable exists
41-
if endpoint:
42-
print(f"The value of ENDPOINT is: {endpoint}")
43-
else:
44-
print("ENDPOINT is not set. Please set the ENDPOINT environment variable to the endpoint of the scheduler")
45-
print("If you are using windows powershell, run the following: $env:ENDPOINT=\"<schedulerEndpoint>\"")
46-
print("If you are using bash, run the following: export ENDPOINT=\"<schedulerEndpoint>\"")
47-
exit()
48-
49-
credential = DefaultAzureCredential()
50-
51-
# configure and start the worker
52-
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
53-
taskhub=taskhub_name, token_credential=credential) as w:
54-
w.add_orchestrator(sequence)
55-
w.add_activity(hello)
56-
w.start()
57-
58-
# Construct the client and run the orchestrations
59-
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
60-
taskhub=taskhub_name, token_credential=credential)
61-
instance_id = c.schedule_new_orchestration(sequence)
62-
state = c.wait_for_orchestration_completion(instance_id, timeout=60)
63-
if state and state.runtime_status == OrchestrationStatus.COMPLETED:
64-
print(f'Orchestration completed! Result: {state.serialized_output}')
65-
elif state:
66-
print(f'Orchestration failed: {state.failure_details}')
1+
"""End-to-end sample that demonstrates how to configure an orchestrator
2+
that calls an activity function in a sequence and prints the outputs."""
3+
import os
4+
from durabletask import task
5+
from durabletask.azuremanaged.worker import DurableTaskSchedulerWorker
6+
from durabletask.azuremanaged.client import DurableTaskSchedulerClient, OrchestrationStatus
7+
from azure.identity import DefaultAzureCredential
8+
9+
def hello(ctx: task.ActivityContext, name: str) -> str:
10+
"""Activity function that returns a greeting"""
11+
return f'Hello {name}!'
12+
13+
14+
def sequence(ctx: task.OrchestrationContext, _):
15+
"""Orchestrator function that calls the 'hello' activity function in a sequence"""
16+
# call "hello" activity function in a sequence
17+
result1 = yield ctx.call_activity(hello, input='Tokyo')
18+
result2 = yield ctx.call_activity(hello, input='Seattle')
19+
result3 = yield ctx.call_activity(hello, input='London')
20+
21+
# return an array of results
22+
return [result1, result2, result3]
23+
24+
25+
# Read the environment variable
26+
taskhub_name = os.getenv("TASKHUB")
27+
28+
# Check if the variable exists
29+
if taskhub_name:
30+
print(f"The value of TASKHUB is: {taskhub_name}")
31+
else:
32+
print("TASKHUB is not set. Please set the TASKHUB environment variable to the name of the taskhub you wish to use")
33+
print("If you are using windows powershell, run the following: $env:TASKHUB=\"<taskhubname>\"")
34+
print("If you are using bash, run the following: export TASKHUB=\"<taskhubname>\"")
35+
exit()
36+
37+
# Read the environment variable
38+
endpoint = os.getenv("ENDPOINT")
39+
40+
# Check if the variable exists
41+
if endpoint:
42+
print(f"The value of ENDPOINT is: {endpoint}")
43+
else:
44+
print("ENDPOINT is not set. Please set the ENDPOINT environment variable to the endpoint of the scheduler")
45+
print("If you are using windows powershell, run the following: $env:ENDPOINT=\"<schedulerEndpoint>\"")
46+
print("If you are using bash, run the following: export ENDPOINT=\"<schedulerEndpoint>\"")
47+
exit()
48+
49+
credential = DefaultAzureCredential()
50+
51+
# configure and start the worker
52+
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
53+
taskhub=taskhub_name, token_credential=credential) as w:
54+
w.add_orchestrator(sequence)
55+
w.add_activity(hello)
56+
w.start()
57+
58+
# Construct the client and run the orchestrations
59+
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
60+
taskhub=taskhub_name, token_credential=credential)
61+
instance_id = c.schedule_new_orchestration(sequence)
62+
state = c.wait_for_orchestration_completion(instance_id, timeout=60)
63+
if state and state.runtime_status == OrchestrationStatus.COMPLETED:
64+
print(f'Orchestration completed! Result: {state.serialized_output}')
65+
elif state:
66+
print(f'Orchestration failed: {state.failure_details}')

0 commit comments

Comments
 (0)