forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_profile.py
More file actions
52 lines (40 loc) · 1.57 KB
/
load_profile.py
File metadata and controls
52 lines (40 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
This sample demonstrates loading a named environment configuration profile and
programmatically overriding its values.
"""
import asyncio
from pathlib import Path
from temporalio.client import Client
from temporalio.envconfig import ClientConfig
async def main():
"""
Demonstrates loading a named profile and overriding values programmatically.
"""
print("--- Loading 'staging' profile with programmatic overrides ---")
config_file = Path(__file__).parent / "config.toml"
profile_name = "staging"
print(
"The 'staging' profile in config.toml has an incorrect address (localhost:9999)."
)
print("We'll programmatically override it to the correct address.")
# Load the 'staging' profile.
connect_config = ClientConfig.load_client_connect_config(
profile=profile_name,
config_file=str(config_file),
)
# Override the target host to the correct address.
# This is the recommended way to override configuration values.
connect_config["target_host"] = "localhost:7233"
print(f"\nLoaded '{profile_name}' profile from {config_file} with overrides.")
print(
f" Address: {connect_config.get('target_host')} (overridden from localhost:9999)"
)
print(f" Namespace: {connect_config.get('namespace')}")
print("\nAttempting to connect to client...")
try:
await Client.connect(**connect_config) # type: ignore
print("✅ Client connected successfully!")
except Exception as e:
print(f"❌ Failed to connect: {e}")
if __name__ == "__main__":
asyncio.run(main())