You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -39,13 +39,14 @@ The Dapr sidecar doesn’t load any workflow definitions. Rather, the sidecar si
39
39
Define the workflow activities you'd like your workflow to perform. Activities are a function definition and can take inputs and outputs. The following example creates a counter (activity) called `hello_act` that notifies users of the current counter value. `hello_act` is a function derived from a class called `WorkflowActivityContext`.
print(f'New counter value is: {counter}!', flush=True)
46
47
```
47
48
48
-
[See the `hello_act`workflow activity in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL40C1-L43C59)
49
+
[See the task chaining workflow activity in context.](https://github.com/dapr/python-sdk/blob/main/examples/workflow/simple.py)
49
50
50
51
51
52
{{% /codetab %}}
@@ -226,19 +227,32 @@ Next, register and call the activites in a workflow.
226
227
227
228
<!--python-->
228
229
229
-
The `hello_world_wf` function is derived from a class called `DaprWorkflowContext` with input and output parameter types. It also includes a `yield` statement that does the heavy lifting of the workflow and calls the workflow activities.
230
+
The `hello_world_wf` function is a function derived from a class called `DaprWorkflowContext` with input and output parameter types. It also includes a `yield` statement that does the heavy lifting of the workflow and calls the workflow activities.
# Change in event handling: Use when_any to handle both event and timeout
242
+
event = ctx.wait_for_external_event(event_name)
243
+
timeout = ctx.create_timer(timedelta(seconds=30))
244
+
winner =yield when_any([event, timeout])
245
+
246
+
if winner == timeout:
247
+
print('Workflow timed out waiting for event')
248
+
return'Timeout'
249
+
237
250
yield ctx.call_activity(hello_act, input=100)
238
251
yield ctx.call_activity(hello_act, input=1000)
252
+
return'Completed'
239
253
```
240
254
241
-
[See the `hello_world_wf` workflow in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL32C1-L38C51)
255
+
[See the `hello_world_wf` workflow in context.](https://github.com/dapr/python-sdk/blob/main/examples/workflow/simple.py)
242
256
243
257
244
258
{{% /codetab %}}
@@ -405,89 +419,177 @@ Finally, compose the application using the workflow.
405
419
406
420
<!--python-->
407
421
408
-
[In the following example](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py), for a basic Python hello world application using the Python SDK, your project code would include:
422
+
[In the following example](https://github.com/dapr/python-sdk/blob/main/examples/workflow/simple.py), for a basic Python hello world application using the Python SDK, your project code would include:
409
423
410
424
- A Python package called `DaprClient` to receive the Python SDK capabilities.
411
425
- A builder with extensions called:
412
-
-`WorkflowRuntime`: Allows you to register workflows and workflow activities
426
+
-`WorkflowRuntime`: Allows you to register the workflow runtime.
413
427
-`DaprWorkflowContext`: Allows you to [create workflows]({{< ref "#write-the-workflow" >}})
414
428
-`WorkflowActivityContext`: Allows you to [create workflow activities]({{< ref "#write-the-workflow-activities" >}})
415
-
- API calls. In the example below, these calls start, pause, resume, purge, and terminate the workflow.
429
+
- API calls. In the example below, these calls start, pause, resume, purge, and completing the workflow.
416
430
417
431
```python
418
-
from dapr.ext.workflow import WorkflowRuntime, DaprWorkflowContext, WorkflowActivityContext
419
-
from dapr.clients import DaprClient
432
+
from datetime import timedelta
433
+
from time import sleep
434
+
from dapr.ext.workflow import (
435
+
WorkflowRuntime,
436
+
DaprWorkflowContext,
437
+
WorkflowActivityContext,
438
+
RetryPolicy,
439
+
DaprWorkflowClient,
440
+
when_any,
441
+
)
442
+
from dapr.conf import Settings
443
+
from dapr.clients.exceptions import DaprInternalError
Copy file name to clipboardExpand all lines: daprdocs/content/en/developing-applications/building-blocks/workflow/howto-manage-workflow.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,13 @@ Now that you've [authored the workflow and its activities in your application]({
14
14
{{% codetab %}}
15
15
16
16
Manage your workflow within your code. In the workflow example from the [Author a workflow]({{< ref "howto-author-workflow.md#write-the-application" >}}) guide, the workflow is registered in the code using the following APIs:
17
-
-**start_workflow**: Start an instance of a workflow
18
-
-**get_workflow**: Get information on the status of the workflow
17
+
-**schedule_new_workflow**: Start an instance of a workflow
18
+
-**get_workflow_state**: Get information on the status of the workflow
19
19
-**pause_workflow**: Pauses or suspends a workflow instance that can later be resumed
20
20
-**resume_workflow**: Resumes a paused workflow instance
21
21
-**raise_workflow_event**: Raise an event on a workflow
22
22
-**purge_workflow**: Removes all metadata related to a specific workflow instance
23
-
-**terminate_workflow**: Terminate or stop a particular instance of a workflow
23
+
-**wait_for_workflow_completion**: Complete a particular instance of a workflow
24
24
25
25
```python
26
26
from dapr.ext.workflow import WorkflowRuntime, DaprWorkflowContext, WorkflowActivityContext
0 commit comments