Skip to content

Update hello_search_attributes.py with new typed search attribute syntax #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions hello/hello_search_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker
from temporalio.common import SearchAttributeKey


@workflow.defn
Expand All @@ -11,7 +12,9 @@ class GreetingWorkflow:
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"]})
workflow.upsert_search_attributes([
SearchAttributeKey.for_keyword("CustomKeywordField").value_set("new-value")
])


async def main():
Expand All @@ -28,23 +31,26 @@ async def main():
# 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.
custom_keyword_field = SearchAttributeKey.for_keyword("CustomKeywordField")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could even make this a global if you'd like and reuse it in the workflow too. At the very least, define it at the top of this function instead of redefining within the function.


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"]},
search_attributes=custom_keyword_field.value_set("old-value"),
)

# Show search attributes before and after a few seconds
custom_keyword_field = SearchAttributeKey.for_keyword("CustomKeywordField")
print(
"First search attribute values: ",
(await handle.describe()).search_attributes.get("CustomKeywordField"),
(await handle.describe()).typed_search_attributes.get(custom_keyword_field),
)
await asyncio.sleep(3)
print(
"Second search attribute values: ",
(await handle.describe()).search_attributes.get("CustomKeywordField"),
(await handle.describe()).typed_search_attributes.get(custom_keyword_field),
)


Expand Down
Loading