@@ -622,20 +622,30 @@ def make_start_op(workflow_id: str):
622622 )
623623
624624
625+ @dataclass
626+ class WorkflowResult :
627+ result : str
628+
629+
630+ @dataclass
631+ class UpdateResult :
632+ result : str
633+
634+
625635@workflow .defn
626636class NoParamWorkflow :
627637 def __init__ (self ) -> None :
628638 self .received_update = False
629639
630640 @workflow .run
631- async def run (self ) -> str :
641+ async def my_workflow_run (self ) -> WorkflowResult :
632642 await workflow .wait_condition (lambda : self .received_update )
633- return "workflow-result"
643+ return WorkflowResult ( result = "workflow-result" )
634644
635- @workflow .update
636- async def update (self ) -> str :
645+ @workflow .update ( name = "my_update" )
646+ async def update (self ) -> UpdateResult :
637647 self .received_update = True
638- return "update-result"
648+ return UpdateResult ( result = "update-result" )
639649
640650
641651@workflow .defn
@@ -644,14 +654,14 @@ def __init__(self) -> None:
644654 self .received_update = False
645655
646656 @workflow .run
647- async def run (self , arg : str ) -> str :
657+ async def my_workflow_run (self , arg : str ) -> WorkflowResult :
648658 await workflow .wait_condition (lambda : self .received_update )
649- return arg
659+ return WorkflowResult ( result = arg )
650660
651- @workflow .update
652- async def update (self , arg : str ) -> str :
661+ @workflow .update ( name = "my_update" )
662+ async def update (self , arg : str ) -> UpdateResult :
653663 self .received_update = True
654- return arg
664+ return UpdateResult ( result = arg )
655665
656666
657667@workflow .defn
@@ -660,14 +670,14 @@ def __init__(self) -> None:
660670 self .received_update = False
661671
662672 @workflow .run
663- async def run (self , arg1 : str , arg2 : str ) -> str :
673+ async def my_workflow_run (self , arg1 : str , arg2 : str ) -> WorkflowResult :
664674 await workflow .wait_condition (lambda : self .received_update )
665- return arg1 + "-" + arg2
675+ return WorkflowResult ( result = arg1 + "-" + arg2 )
666676
667- @workflow .update
668- async def update (self , arg1 : str , arg2 : str ) -> str :
677+ @workflow .update ( name = "my_update" )
678+ async def update (self , arg1 : str , arg2 : str ) -> UpdateResult :
669679 self .received_update = True
670- return arg1 + "-" + arg2
680+ return UpdateResult ( result = arg1 + "-" + arg2 )
671681
672682
673683async def test_update_with_start_overloads (client : Client ):
@@ -677,101 +687,120 @@ async def test_update_with_start_overloads(client: Client):
677687 OneParamWorkflow ,
678688 TwoParamWorkflow ,
679689 ) as worker :
680-
681- def make_no_param_start_op (workflow_id : str ):
682- return WithStartWorkflowOperation (
683- NoParamWorkflow .run ,
684- id = workflow_id ,
685- task_queue = worker .task_queue ,
686- id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
687- )
688-
689- def make_one_param_start_op (workflow_id : str ):
690- return WithStartWorkflowOperation (
691- OneParamWorkflow .run ,
692- "workflow-arg" ,
693- id = workflow_id ,
694- task_queue = worker .task_queue ,
695- id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
696- )
697-
698- def make_two_param_start_op (workflow_id : str ):
699- return WithStartWorkflowOperation (
700- TwoParamWorkflow .run ,
701- args = ("workflow-arg1" , "workflow-arg2" ),
702- id = workflow_id ,
703- task_queue = worker .task_queue ,
704- id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
705- )
706-
707690 # No-params typed
708- no_param_start_op = make_no_param_start_op (f"wf-{ uuid .uuid4 ()} " )
691+ no_param_start_op = WithStartWorkflowOperation (
692+ NoParamWorkflow .my_workflow_run ,
693+ id = f"wf-{ uuid .uuid4 ()} " ,
694+ task_queue = worker .task_queue ,
695+ id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
696+ )
709697 update_handle = await client .start_update_with_start_workflow (
710698 NoParamWorkflow .update ,
711699 wait_for_stage = WorkflowUpdateStage .COMPLETED ,
712700 start_workflow_operation = no_param_start_op ,
713701 )
714- assert await update_handle .result () == "update-result"
702+ assert await update_handle .result () == UpdateResult ( result = "update-result" )
715703 wf_handle = await no_param_start_op .workflow_handle ()
716- assert await wf_handle .result () == "workflow-result"
704+ assert await wf_handle .result () == WorkflowResult ( result = "workflow-result" )
717705
718706 # No-params string name
719- no_param_start_op = make_no_param_start_op (f"wf-{ uuid .uuid4 ()} " )
707+ no_param_start_op = WithStartWorkflowOperation (
708+ "NoParamWorkflow" ,
709+ id = f"wf-{ uuid .uuid4 ()} " ,
710+ task_queue = worker .task_queue ,
711+ id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
712+ result_type = WorkflowResult ,
713+ )
720714 update_handle = await client .start_update_with_start_workflow (
721- "update " ,
715+ "my_update " ,
722716 wait_for_stage = WorkflowUpdateStage .COMPLETED ,
723717 start_workflow_operation = no_param_start_op ,
718+ result_type = UpdateResult ,
724719 )
725- assert await update_handle .result () == "update-result"
720+ assert await update_handle .result () == UpdateResult ( result = "update-result" )
726721 wf_handle = await no_param_start_op .workflow_handle ()
727- assert await wf_handle .result () == "workflow-result"
722+ assert await wf_handle .result () == WorkflowResult ( result = "workflow-result" )
728723
729724 # One-param typed
730- one_param_start_op = make_one_param_start_op (f"wf-{ uuid .uuid4 ()} " )
725+ one_param_start_op = WithStartWorkflowOperation (
726+ OneParamWorkflow .my_workflow_run ,
727+ "workflow-arg" ,
728+ id = f"wf-{ uuid .uuid4 ()} " ,
729+ task_queue = worker .task_queue ,
730+ id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
731+ )
731732 update_handle = await client .start_update_with_start_workflow (
732733 OneParamWorkflow .update ,
733734 "update-arg" ,
734735 wait_for_stage = WorkflowUpdateStage .COMPLETED ,
735736 start_workflow_operation = one_param_start_op ,
736737 )
737- assert await update_handle .result () == "update-arg"
738+ assert await update_handle .result () == UpdateResult ( result = "update-arg" )
738739 wf_handle = await one_param_start_op .workflow_handle ()
739- assert await wf_handle .result () == "workflow-arg"
740+ assert await wf_handle .result () == WorkflowResult ( result = "workflow-arg" )
740741
741742 # One-param string name
742- one_param_start_op = make_one_param_start_op (f"wf-{ uuid .uuid4 ()} " )
743+ one_param_start_op = WithStartWorkflowOperation (
744+ "OneParamWorkflow" ,
745+ "workflow-arg" ,
746+ id = f"wf-{ uuid .uuid4 ()} " ,
747+ task_queue = worker .task_queue ,
748+ id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
749+ result_type = WorkflowResult ,
750+ )
743751 update_handle = await client .start_update_with_start_workflow (
744- "update " ,
752+ "my_update " ,
745753 "update-arg" ,
746754 wait_for_stage = WorkflowUpdateStage .COMPLETED ,
747755 start_workflow_operation = one_param_start_op ,
756+ result_type = UpdateResult ,
748757 )
749- assert await update_handle .result () == "update-arg"
758+ assert await update_handle .result () == UpdateResult ( result = "update-arg" )
750759 wf_handle = await one_param_start_op .workflow_handle ()
751- assert await wf_handle .result () == "workflow-arg"
760+ assert await wf_handle .result () == WorkflowResult ( result = "workflow-arg" )
752761
753762 # Two-params typed
754- two_param_start_op = make_two_param_start_op (f"wf-{ uuid .uuid4 ()} " )
763+ two_param_start_op = WithStartWorkflowOperation (
764+ TwoParamWorkflow .my_workflow_run ,
765+ args = ("workflow-arg1" , "workflow-arg2" ),
766+ id = f"wf-{ uuid .uuid4 ()} " ,
767+ task_queue = worker .task_queue ,
768+ id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
769+ )
755770 update_handle = await client .start_update_with_start_workflow (
756771 TwoParamWorkflow .update ,
757772 args = ("update-arg1" , "update-arg2" ),
758773 wait_for_stage = WorkflowUpdateStage .COMPLETED ,
759774 start_workflow_operation = two_param_start_op ,
760775 )
761- assert await update_handle .result () == "update-arg1-update-arg2"
762-
776+ assert await update_handle .result () == UpdateResult (
777+ result = "update-arg1-update-arg2"
778+ )
763779 wf_handle = await two_param_start_op .workflow_handle ()
764- assert await wf_handle .result () == "workflow-arg1-workflow-arg2"
780+ assert await wf_handle .result () == WorkflowResult (
781+ result = "workflow-arg1-workflow-arg2"
782+ )
765783
766784 # Two-params string name
767- two_param_start_op = make_two_param_start_op (f"wf-{ uuid .uuid4 ()} " )
785+ two_param_start_op = WithStartWorkflowOperation (
786+ "TwoParamWorkflow" ,
787+ args = ("workflow-arg1" , "workflow-arg2" ),
788+ id = f"wf-{ uuid .uuid4 ()} " ,
789+ task_queue = worker .task_queue ,
790+ id_conflict_policy = WorkflowIDConflictPolicy .FAIL ,
791+ result_type = WorkflowResult ,
792+ )
768793 update_handle = await client .start_update_with_start_workflow (
769- "update " ,
794+ "my_update " ,
770795 args = ("update-arg1" , "update-arg2" ),
771796 wait_for_stage = WorkflowUpdateStage .COMPLETED ,
772797 start_workflow_operation = two_param_start_op ,
798+ result_type = UpdateResult ,
799+ )
800+ assert await update_handle .result () == UpdateResult (
801+ result = "update-arg1-update-arg2"
773802 )
774- assert await update_handle .result () == "update-arg1-update-arg2"
775-
776803 wf_handle = await two_param_start_op .workflow_handle ()
777- assert await wf_handle .result () == "workflow-arg1-workflow-arg2"
804+ assert await wf_handle .result () == WorkflowResult (
805+ result = "workflow-arg1-workflow-arg2"
806+ )
0 commit comments