diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-author-workflow.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-author-workflow.md index 543bb1c17..e30fec575 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-author-workflow.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-author-workflow.md @@ -163,15 +163,8 @@ app.Run(); - A Python package called `DaprClient` to receive the Python SDK capabilities - A builder with an extension method called `todo` - This will allow you to register workflows and workflow activities (tasks that workflows can schedule) -- HTTP API calls - - **start_workflow**: Start an instance of a workflow - - **get_workflow**: Get information on a single workflow - - **terminate_workflow**: Terminate or stop a particular instance of a workflow - - **raise_event**: Raise an event on a workflow - - **pause_workflow**: Pauses or suspends a workflow instance that can later be resumed - - **resume_workflow**: Resumes a paused workflow instance - - **purge_workflow**: Removes all metadata related to a specific workflow instance - +- HTTP API calls to start, pause, resume, terminate, and purge the workflow. + ```python from dapr.clients import DaprClient @@ -198,28 +191,9 @@ with DaprClient() as d: workflow_name=workflowName, input=encoded_data2, workflow_options=workflowOptions) print(f"Attempting to start {workflowName}") print(f"start_resp {start_resp.instance_id}") + # Get workflow status getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) print(f"Get response from {workflowName} after start call: {getResponse.runtime_status}") - - # Pause Test - d.pause_workflow(instance_id=instanceId, workflow_component=workflowComponent) - getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) - print(f"Get response from {workflowName} after pause call: {getResponse.runtime_status}") - - # Resume Test - d.resume_workflow(instance_id=instanceId, workflow_component=workflowComponent) - getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) - print(f"Get response from {workflowName} after resume call: {getResponse.runtime_status}") - - # Terminate Test - d.terminate_workflow(instance_id=instanceId, workflow_component=workflowComponent) - getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) - print(f"Get response from {workflowName} after terminate call: {getResponse.runtime_status}") - - # Purge Test - d.purge_workflow(instance_id=instanceId, workflow_component=workflowComponent) - getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) - print(f"Get response from {workflowName} after purge call: {getResponse}") ``` diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-manage-workflow.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-manage-workflow.md index b876c5d9f..5b5359277 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-manage-workflow.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/howto-manage-workflow.md @@ -8,7 +8,7 @@ description: Manage and run workflows Now that you've [authored the workflow and its activities in your application]({{< ref howto-author-workflow.md >}}), you can start, terminate, and get information about the workflow using HTTP API calls. For more information, read the [workflow API reference]({{< ref workflow_api.md >}}). -{{< tabs ".NET SDK" HTTP >}} +{{< tabs ".NET SDK" "Python SDK" HTTP >}} {{% codetab %}} @@ -35,6 +35,72 @@ await daprClient.TerminateWorkflowAsync(instanceId, workflowComponent); {{% /codetab %}} + +{{% codetab %}} + +Manage your workflow within your code. In the `OrderProcessingWorkflow` example from the [Author a workflow]({{< ref "howto-author-workflow.md#write-the-workflow" >}}) guide, the workflow is registered in the code using the following APIs: +- **start_workflow**: Start an instance of a workflow +- **get_workflow**: Get information on a single workflow +- **terminate_workflow**: Terminate or stop a particular instance of a workflow +- **raise_event**: Raise an event on a workflow +- **pause_workflow**: Pauses or suspends a workflow instance that can later be resumed +- **resume_workflow**: Resumes a paused workflow instance +- **purge_workflow**: Removes all metadata related to a specific workflow instance + +```python +from dapr.clients import DaprClient + +from dapr.clients.grpc._helpers import to_bytes +# ... + +# Dapr Workflows are registered as part of the service configuration +with DaprClient() as d: + instanceId = "RRLINSTANCEID35" + workflowComponent = "dapr" + workflowName = "PlaceOrder" + workflowOptions = dict() + workflowOptions["task_queue"] = "testQueue" + inventoryItem = ("Computers", 5, 10) + item2 = "paperclips" + + encoded_data = b''.join(bytes(str(element), 'UTF-8') for element in item2) + encoded_data2 = json.dumps(item2).encode("UTF-8") + + # ... + + # Start the workflow + start_resp = d.start_workflow(instance_id=instanceId, workflow_component=workflowComponent, + workflow_name=workflowName, input=encoded_data2, workflow_options=workflowOptions) + print(f"Attempting to start {workflowName}") + print(f"start_resp {start_resp.instance_id}") + # Get workflow status + getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) + print(f"Get response from {workflowName} after start call: {getResponse.runtime_status}") + + # Pause Test + d.pause_workflow(instance_id=instanceId, workflow_component=workflowComponent) + getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) + print(f"Get response from {workflowName} after pause call: {getResponse.runtime_status}") + + # Resume Test + d.resume_workflow(instance_id=instanceId, workflow_component=workflowComponent) + getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) + print(f"Get response from {workflowName} after resume call: {getResponse.runtime_status}") + + # Terminate Test + d.terminate_workflow(instance_id=instanceId, workflow_component=workflowComponent) + getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) + print(f"Get response from {workflowName} after terminate call: {getResponse.runtime_status}") + + # Purge Test + d.purge_workflow(instance_id=instanceId, workflow_component=workflowComponent) + getResponse = d.get_workflow(instance_id=instanceId, workflow_component=workflowComponent) + print(f"Get response from {workflowName} after purge call: {getResponse}") +``` + +{{% /codetab %}} + + {{% codetab %}} @@ -74,5 +140,7 @@ Learn more about these HTTP calls in the [workflow API reference guide]({{< ref ## Next steps - [Try out the Workflow quickstart]({{< ref workflow-quickstart.md >}}) -- [Try out the .NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) +- Try out the full SDK examples: + - [.NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) + - [Python example](todo) - [Workflow API reference]({{< ref workflow_api.md >}}) diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-overview.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-overview.md index 5afd25055..d2fe7664b 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-overview.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-overview.md @@ -81,6 +81,8 @@ You can use the following SDKs to author a workflow. | Language stack | Package | | - | - | | .NET | [Dapr.Workflow](https://www.nuget.org/profiles/dapr.io) | +| Python | [StartWorkflowResponse](todo) | + ## Try out workflows @@ -92,6 +94,8 @@ Want to put workflows to the test? Walk through the following quickstart and tut | ------------------- | ----------- | | [Workflow quickstart]({{< ref workflow-quickstart.md >}}) | Run a .NET workflow application with four workflow activities to see Dapr Workflow in action | | [Workflow .NET SDK example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) | Learn how to create a Dapr Workflow and invoke it using ASP.NET Core web APIs. | +| [Workflow Python SDK example](todo) | Learn how to create a Dapr Workflow and invoke it using ASP.NET Core web APIs. | + ### Start using workflows directly in your app @@ -110,4 +114,6 @@ Watch [this video for an overview on Dapr Workflow](https://youtu.be/s1p9MNl4VGo ## Related links - [Workflow API reference]({{< ref workflow_api.md >}}) -- [Try out the .NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) +- Try out the full SDK examples: + - [.NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) + - [Python example](todo)