mirror of https://github.com/dapr/quickstarts.git
Add comments and types
Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com>
This commit is contained in:
parent
757d318d8a
commit
6b06b9c52d
|
@ -3,19 +3,37 @@ from dapr.ext.workflow import DaprWorkflowContext, WorkflowActivityContext, Work
|
|||
|
||||
wf_runtime = WorkflowRuntime()
|
||||
|
||||
"""
|
||||
Workflows orchestrate activities and other (child)workflows, and include business logic (if/else or switch statements).
|
||||
Workflow code must be be deterministic. Any non-deterministic behavior should be written inside activities.
|
||||
|
||||
Workflow definitions use the `workflow` decorator to define a workflow.
|
||||
The first argument (`ctx`) is the `DaprWorkflowContext`, this contains properties
|
||||
about the workflow instance, and methods to call activities.
|
||||
The second argument (`wf_input`) is the input to the workflow. It can be a simple or complex type.
|
||||
"""
|
||||
@wf_runtime.workflow(name='basic_workflow')
|
||||
def basic_workflow(ctx: DaprWorkflowContext, wf_input: str):
|
||||
result1 = yield ctx.call_activity(activity1, input=wf_input)
|
||||
result2 = yield ctx.call_activity(activity2, input=result1)
|
||||
|
||||
return result2
|
||||
|
||||
"""
|
||||
Activity code typically performs a one specific task, like calling an API to store or retrieve data.
|
||||
You can use other Dapr APIs inside an activity.
|
||||
|
||||
Activity definitions use the `activity` decorator to define an activity.
|
||||
The first argument (`ctx`) is the `WorkflowActivityContext` and provides
|
||||
the name of the activity and the workflow instance.
|
||||
The second argument (`act_input`) is the input parameter for the activity.
|
||||
There can only be one input parameter. Use a class if multiple input values are required.
|
||||
"""
|
||||
@wf_runtime.activity(name='activity1')
|
||||
def activity1(ctx: WorkflowActivityContext, input):
|
||||
print(f'activity1: Received input: {input}.')
|
||||
return f"{input} Two"
|
||||
def activity1(ctx: WorkflowActivityContext, act_input: str) -> str:
|
||||
print(f'activity1: Received input: {act_input}.')
|
||||
return f"{act_input} Two"
|
||||
|
||||
@wf_runtime.activity(name='activity2')
|
||||
def activity2(ctx: WorkflowActivityContext, input):
|
||||
print(f'activity2: Received input: {input}.')
|
||||
return f"{input} Three"
|
||||
def activity2(ctx: WorkflowActivityContext, act_input: str) -> str:
|
||||
print(f'activity2: Received input: {act_input}.')
|
||||
return f"{act_input} Three"
|
Loading…
Reference in New Issue