Skip to content

Commit c4b1009

Browse files
committed
update samples to use environment configuration for client
1 parent 6d05457 commit c4b1009

File tree

108 files changed

+975
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+975
-180
lines changed

activity_worker/activity_worker.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import asyncio
22
import random
33
import string
4+
from pathlib import Path
45

56
from temporalio import activity
67
from temporalio.client import Client
8+
from temporalio.envconfig import ClientConfig
79
from temporalio.worker import Worker
810

911
task_queue = "say-hello-task-queue"
@@ -18,7 +20,12 @@ async def say_hello_activity(name: str) -> str:
1820

1921
async def main():
2022
# Create client to localhost on default namespace
21-
client = await Client.connect("localhost:7233")
23+
# Get repo root - 1 level deep from root
24+
repo_root = Path(__file__).resolve().parent.parent
25+
config_file = repo_root / "temporal.toml"
26+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
27+
config["target_host"] = "localhost:7233"
28+
client = await Client.connect(**config)
2229

2330
# Run activity worker
2431
async with Worker(client, task_queue=task_queue, activities=[say_hello_activity]):

batch_sliding_window/starter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ async def main():
1919
logging.basicConfig(level=logging.INFO)
2020

2121
# Create client
22-
client = await Client.connect("localhost:7233")
22+
# Get repo root - 1 level deep from root
23+
repo_root = Path(__file__).resolve().parent.parent
24+
config_file = repo_root / "temporal.toml"
25+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
26+
config["target_host"] = "localhost:7233"
27+
client = await Client.connect(**config)
2328

2429
# Create unique workflow ID with timestamp
2530
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")

batch_sliding_window/worker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ async def main():
1919
logging.basicConfig(level=logging.INFO)
2020

2121
# Create client
22-
client = await Client.connect("localhost:7233")
22+
# Get repo root - 1 level deep from root
23+
repo_root = Path(__file__).resolve().parent.parent
24+
config_file = repo_root / "temporal.toml"
25+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
26+
config["target_host"] = "localhost:7233"
27+
client = await Client.connect(**config)
2328

2429
# Create RecordLoader activity with sample data
2530
record_loader = RecordLoader(record_count=90)

bedrock/basic/run_worker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
async def main():
1313
# Create client connected to server at the given address
14-
client = await Client.connect("localhost:7233")
14+
# Get repo root - 2 levels deep from root
15+
repo_root = Path(__file__).resolve().parent.parent.parent
16+
config_file = repo_root / "temporal.toml"
17+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
18+
config["target_host"] = "localhost:7233"
19+
client = await Client.connect(**config)
1520
activities = BedrockActivities()
1621

1722
# Run the worker

bedrock/basic/send_message.py

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

88
async def main(prompt: str) -> str:
99
# Create client connected to server at the given address
10-
client = await Client.connect("localhost:7233")
10+
# Get repo root - 2 levels deep from root
11+
repo_root = Path(__file__).resolve().parent.parent.parent
12+
config_file = repo_root / "temporal.toml"
13+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
14+
config["target_host"] = "localhost:7233"
15+
client = await Client.connect(**config)
1116

1217
# Start the workflow
1318
workflow_id = "basic-bedrock-workflow"

bedrock/entity/end_chat.py

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

88
async def main():
99
# Create client connected to server at the given address
10-
client = await Client.connect("localhost:7233")
10+
# Get repo root - 2 levels deep from root
11+
repo_root = Path(__file__).resolve().parent.parent.parent
12+
config_file = repo_root / "temporal.toml"
13+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
14+
config["target_host"] = "localhost:7233"
15+
client = await Client.connect(**config)
1116

1217
workflow_id = "entity-bedrock-workflow"
1318

bedrock/entity/get_history.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
async def main():
88
# Create client connected to server at the given address
9-
client = await Client.connect("localhost:7233")
9+
# Get repo root - 2 levels deep from root
10+
repo_root = Path(__file__).resolve().parent.parent.parent
11+
config_file = repo_root / "temporal.toml"
12+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
13+
config["target_host"] = "localhost:7233"
14+
client = await Client.connect(**config)
1015
workflow_id = "entity-bedrock-workflow"
1116

1217
handle = client.get_workflow_handle(workflow_id)

bedrock/entity/run_worker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
async def main():
1313
# Create client connected to server at the given address
14-
client = await Client.connect("localhost:7233")
14+
# Get repo root - 2 levels deep from root
15+
repo_root = Path(__file__).resolve().parent.parent.parent
16+
config_file = repo_root / "temporal.toml"
17+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
18+
config["target_host"] = "localhost:7233"
19+
client = await Client.connect(**config)
1520
activities = BedrockActivities()
1621

1722
# Run the worker

bedrock/entity/send_message.py

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

88
async def main(prompt):
99
# Create client connected to server at the given address
10-
client = await Client.connect("localhost:7233")
10+
# Get repo root - 2 levels deep from root
11+
repo_root = Path(__file__).resolve().parent.parent.parent
12+
config_file = repo_root / "temporal.toml"
13+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
14+
config["target_host"] = "localhost:7233"
15+
client = await Client.connect(**config)
1116

1217
workflow_id = "entity-bedrock-workflow"
1318

bedrock/signals_and_queries/get_history.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
async def main():
88
# Create client connected to server at the given address
9-
client = await Client.connect("localhost:7233")
9+
# Get repo root - 2 levels deep from root
10+
repo_root = Path(__file__).resolve().parent.parent.parent
11+
config_file = repo_root / "temporal.toml"
12+
config = ClientConfig.load_client_connect_config(config_file=str(config_file))
13+
config["target_host"] = "localhost:7233"
14+
client = await Client.connect(**config)
1015
workflow_id = "bedrock-workflow-with-signals"
1116

1217
handle = client.get_workflow_handle(workflow_id)

0 commit comments

Comments
 (0)