Skip to content
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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
15 changes: 11 additions & 4 deletions hello/hello_search_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker
from temporalio.common import SearchAttributeKey

# define our custom search attribute to modify later in the workflow
custom_keyword_field = SearchAttributeKey.for_keyword("CustomKeywordField")


@workflow.defn
Expand All @@ -11,7 +15,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([
custom_keyword_field.value_set("new-value")
])


async def main():
Expand All @@ -28,23 +34,24 @@ 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.

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
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