Skip to content

Commit

Permalink
address review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Mukundan Sundararajan <[email protected]>
  • Loading branch information
mukundansundar committed Dec 20, 2023
1 parent 2f26572 commit 286f51b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
23 changes: 12 additions & 11 deletions examples/workflow/child_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,33 @@
import dapr.ext.workflow as wf
import time

wfr = wf.WorkflowRuntime()

@wfr.workflow
def main_workflow(ctx: wf.DaprWorkflowContext):
try:
instance_id = ctx.instance_id
child_instance_id = instance_id + '-child'
print(f'*** Calling child workflow {child_instance_id}')
print(f'*** Calling child workflow {child_instance_id}', flush=True)
yield ctx.call_child_workflow(workflow=child_workflow,input=None,instance_id=child_instance_id)
except Exception as e:
print(f'*** Exception: {e}')

return

@wfr.workflow
def child_workflow(ctx: wf.DaprWorkflowContext):
instance_id = ctx.instance_id
print(f'*** Child workflow {instance_id} called')
print(f'*** Child workflow {instance_id} called', flush=True)

if __name__ == '__main__':
workflowRuntime = wf.WorkflowRuntime("localhost", "50001")
workflowRuntime.register_workflow(main_workflow)
workflowRuntime.register_workflow(child_workflow)
workflowRuntime.start()
wfr.start()
time.sleep(10) # wait for workflow runtime to start

wf_client = wf.DaprWorkflowClient()
instance_id = wf_client.schedule_new_workflow(
workflow=main_workflow)
instance_id = wf_client.schedule_new_workflow(workflow=main_workflow)

# Wait for the workflow to complete
time.sleep(5)
workflowRuntime.shutdown()

wfr.shutdown()
2 changes: 1 addition & 1 deletion examples/workflow/fan_out_fan_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import List
import dapr.ext.workflow as wf

wfr = wf.WorkflowRuntime("localhost", "50001")
wfr = wf.WorkflowRuntime()

@wfr.workflow(name="batch_processing")
def batch_processing_workflow(ctx: wf.DaprWorkflowContext, wf_input: int):
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/human_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from dapr.clients import DaprClient
import dapr.ext.workflow as wf

wfr = wf.WorkflowRuntime("localhost", "50001")
wfr = wf.WorkflowRuntime()

@dataclass
class Order:
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/task_chaining.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import dapr.ext.workflow as wf


wfr = wf.WorkflowRuntime("localhost", "50001")
wfr = wf.WorkflowRuntime()

@wfr.workflow(name="random_workflow")
def task_chain_workflow(ctx: wf.DaprWorkflowContext, wf_input: int):
Expand Down
19 changes: 5 additions & 14 deletions ext/dapr-ext-workflow/dapr/ext/workflow/workflow_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def workflow(self, __fn: Workflow = None, *, name: Optional[str] = None):
def add(ctx, x: int, y: int) -> int:
return x + y
This example shows how to register a workflow function without a name:
This example shows how to register a workflow function without
an alternate name:
from dapr.ext.workflow import WorkflowRuntime
wfr = WorkflowRuntime()
Expand Down Expand Up @@ -157,7 +158,7 @@ def innerfn():
def activity(self, __fn: Activity = None, *, name: Optional[str] = None):
"""Decorator to register an activity function.
This example shows how to register an activity function with a name:
This example shows how to register an activity function with an alternate name:
from dapr.ext.workflow import WorkflowRuntime
wfr = WorkflowRuntime()
Expand All @@ -166,7 +167,7 @@ def activity(self, __fn: Activity = None, *, name: Optional[str] = None):
def add(ctx, x: int, y: int) -> int:
return x + y
This example shows how to register an activity function without a name:
This example shows how to register an activity function without an alternate name:
from dapr.ext.workflow import WorkflowRuntime
wfr = WorkflowRuntime()
Expand Down Expand Up @@ -205,7 +206,7 @@ def innerfn():
def alternate_name(name: Optional[str] = None):
"""Decorator to register a workflow or activity function with an alternate name.
This example shows how to register a workflow function with a name:
This example shows how to register a workflow function with an alternate name:
from dapr.ext.workflow import WorkflowRuntime
wfr = WorkflowRuntime()
Expand All @@ -215,16 +216,6 @@ def alternate_name(name: Optional[str] = None):
def add(ctx, x: int, y: int) -> int:
return x + y
This example shows how to register an activity function with a name:
from dapr.ext.workflow import WorkflowRuntime
wfr = WorkflowRuntime()
@wfr.activity
@alternate_name("add")
def add(ctx, x: int, y: int) -> int:
return x + y
Args:
name (Optional[str], optional): Name to identify the workflow or activity function as in
the workflow runtime. Defaults to None.
Expand Down

0 comments on commit 286f51b

Please sign in to comment.