-
Notifications
You must be signed in to change notification settings - Fork 57
/
hello_search_attributes.py
52 lines (42 loc) · 1.62 KB
/
hello_search_attributes.py
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
import asyncio
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker
@workflow.defn
class GreetingWorkflow:
@workflow.run
async def run(self) -> None:
# Wait a couple seconds, then alter the keyword search attribute
await asyncio.sleep(2)
workflow.upsert_search_attributes({"CustomKeywordField": ["new-value"]})
async def main():
# Start client
client = await Client.connect("localhost:7233")
# Run a worker for the workflow
async with Worker(
client,
task_queue="hello-search-attributes-task-queue",
workflows=[GreetingWorkflow],
):
# While the worker is running, use the client to start the workflow.
# Note, in many production setups, the client would be in a completely
# separate process from the worker.
handle = await client.start_workflow(
GreetingWorkflow.run,
id="hello-search-attributes-workflow-id",
task_queue="hello-search-attributes-task-queue",
# Start with default set of search attributes
search_attributes={"CustomKeywordField": ["old-value"]},
)
# Show search attributes before and after a few seconds
print(
"First search attribute values: ",
(await handle.describe()).search_attributes.get("CustomKeywordField"),
)
await asyncio.sleep(3)
print(
"Second search attribute values: ",
(await handle.describe()).search_attributes.get("CustomKeywordField"),
)
if __name__ == "__main__":
asyncio.run(main())