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

Adds Workflow Update to Samples #99

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions hello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ Replace `hello_activity.py` in the command with any other example filename to ru
* [hello_search_attributes](hello_search_attributes.py) - Start workflow with search attributes then change while
running.
* [hello_signal](hello_signal.py) - Send signals to a workflow.
* [hello_workflow_update](hello_workflow_update.py) - Send a request to and a response from a client to a workflow execution.

Note: To enable the workflow update, set the `frontend.enableUpdateWorkflowExecution` dynamic config value to true.

temporal server start-dev --dynamic-config-value frontend.enableUpdateWorkflowExecution=true
52 changes: 52 additions & 0 deletions hello/hello_workflow_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import asyncio
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker


@workflow.defn
class GreetingWorkflow:
is_complete = False

@workflow.run
async def run(self) -> str:
await workflow.wait_condition(lambda: self.is_complete)
return "Hello, World!"

@workflow.update
async def update_workflow_status(self) -> str:
self.is_complete = True
return "Workflow status updated"


async def main():
client = await Client.connect("localhost:7233")

# Run a worker for the workflow
async with Worker(
client,
task_queue="update-workflow-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-update-workflow-id",
task_queue="update-workflow-task-queue",
)

# Perform the update for GreetingWorkflow
update_result = await handle.execute_update(
GreetingWorkflow.update_workflow_status
)
print(f"Update Result: {update_result}")

# Get the result for GreetingWorkflow
result = await handle.result()
print(f"Workflow Result: {result}")


if __name__ == "__main__":
asyncio.run(main())
Loading