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
@@ -36,31 +36,17 @@ The Dapr sidecar doesn’t load any workflow definitions. Rather, the sidecar si
36
36
37
37
<!--python-->
38
38
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 task chaining activities that receive input
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`.
40
40
41
41
```python
42
-
@wfr.activity(name='step10')
43
-
defstep1(ctx, activity_input):
44
-
print(f'Step 1: Received input: {activity_input}.')
45
-
# Do some work
46
-
return activity_input +1
47
-
48
-
49
-
@wfr.activity
50
-
defstep2(ctx, activity_input):
51
-
print(f'Step 2: Received input: {activity_input}.')
52
-
# Do some work
53
-
return activity_input *2
54
-
55
-
56
-
@wfr.activity
57
-
defstep3(ctx, activity_input):
58
-
print(f'Step 3: Received input: {activity_input}.')
print(f'New counter value is: {counter}!', flush=True)
61
47
```
62
48
63
-
[See the task chaining workflow activity in context.](https://github.com/dapr/python-sdk/blob/main/examples/workflow/task_chaining.py)
49
+
[See the task chaining workflow activity in context.](https://github.com/dapr/python-sdk/blob/main/examples/workflow/simple.py)
64
50
65
51
66
52
{{% /codetab %}}
@@ -241,22 +227,32 @@ Next, register and call the activites in a workflow.
241
227
242
228
<!--python-->
243
229
244
-
The `random_workflow` function is a task chaining workflow pattern 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
+
250
+
yield ctx.call_activity(hello_act, input=100)
251
+
yield ctx.call_activity(hello_act, input=1000)
252
+
return'Completed'
257
253
```
258
254
259
-
[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)
260
256
261
257
262
258
{{% /codetab %}}
@@ -423,84 +419,177 @@ Finally, compose the application using the workflow.
423
419
424
420
<!--python-->
425
421
426
-
[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:
427
423
428
424
- A Python package called `DaprClient` to receive the Python SDK capabilities.
429
425
- A builder with extensions called:
430
426
-`WorkflowRuntime`: Allows you to register the workflow runtime.
431
-
-`DaprWorkflowContext`: Allows you to [create workflows and workflow activities]({{< ref "#write-the-workflow" >}})
427
+
-`DaprWorkflowContext`: Allows you to [create workflows]({{< ref "#write-the-workflow" >}})
432
428
-`WorkflowActivityContext`: Allows you to [create workflow activities]({{< ref "#write-the-workflow-activities" >}})
433
-
- 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.
434
430
435
431
```python
436
-
from durabletask import worker, task
437
-
438
-
from dapr.ext.workflow.workflow_context import Workflow
439
-
from dapr.ext.workflow.dapr_workflow_context import DaprWorkflowContext
440
-
from dapr.ext.workflow.workflow_activity_context import Activity, WorkflowActivityContext
441
-
from dapr.ext.workflow.util import getAddress
442
-
443
-
from dapr.clients import DaprInternalError
444
-
from dapr.clients.http.client importDAPR_API_TOKEN_HEADER
445
-
from dapr.conf import settings
446
-
from dapr.conf.helpers import GrpcEndpoint
447
-
from dapr.ext.workflow.logger import LoggerOptions, Logger
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