-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Workflow Update to Samples (#99)
* Adds Workflow Update to Samples * Move Workflow Update to single file * Update the name of the file and run format
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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()) |