44import com .google .common .base .Strings ;
55import io .nexusrpc .OperationException ;
66import io .nexusrpc .handler .HandlerException ;
7+ import io .nexusrpc .handler .HandlerException .RetryBehavior ;
78import io .nexusrpc .handler .OperationContext ;
89import io .nexusrpc .handler .OperationStartDetails ;
10+ import io .temporal .api .common .v1 .WorkflowExecution ;
911import io .temporal .client .UpdateOptions ;
1012import io .temporal .client .WorkflowClient ;
1113import io .temporal .client .WorkflowOptions ;
1214import io .temporal .client .WorkflowStub ;
15+ import io .temporal .client .WorkflowTargetOptions ;
1316import io .temporal .client .WorkflowUpdateException ;
1417import io .temporal .client .WorkflowUpdateHandle ;
1518import io .temporal .client .WorkflowUpdateStage ;
@@ -596,15 +599,21 @@ private <R> TemporalOperationResult<R> executeUpdate(
596599 private <R > void checkNexusUpdateOptionsValid (UpdateOptions <R > options )
597600 throws OperationException {
598601 if (options .getWaitForStage () != WorkflowUpdateStage .ACCEPTED ) {
599- throw OperationException .failed (
600- "workflow update Nexus operation only support WaitForStage Accepted" );
602+ throw new HandlerException (
603+ HandlerException .ErrorType .BAD_REQUEST ,
604+ "invalid update request" ,
605+ new IllegalArgumentException (
606+ "nexus op workflow updates only support WorkflowUpdateStageAccepted for async updates" ),
607+ RetryBehavior .RETRYABLE );
601608 }
602- // draft-review: TBD, this is still under discussion as we may want to let
603- // handlers trigger invalid updates in some cases and just retry forever
604609 try {
605610 options .validate ();
606611 } catch (IllegalStateException e ) {
607- throw OperationException .failed (e );
612+ throw new HandlerException (
613+ HandlerException .ErrorType .INTERNAL ,
614+ "invalid update request" ,
615+ e ,
616+ RetryBehavior .RETRYABLE );
608617 }
609618 }
610619
@@ -617,4 +626,28 @@ private void markAsyncOperationStarted() {
617626 + "Use getWorkflowClient() for additional workflow interactions." ));
618627 }
619628 }
629+
630+ @ Override
631+ public <T , A1 , A2 , A3 , A4 , A5 , A6 , R > TemporalOperationResult <R > startWorkflowUpdate (
632+ Class <T > workflowClass ,
633+ WorkflowExecution execution ,
634+ Functions .Func7 <T , A1 , A2 , A3 , A4 , A5 , A6 , R > updateMethod ,
635+ A1 arg1 ,
636+ A2 arg2 ,
637+ A3 arg3 ,
638+ A4 arg4 ,
639+ A5 arg5 ,
640+ A6 arg6 ,
641+ UpdateOptions <R > options )
642+ throws OperationException {
643+ T stub =
644+ client .newWorkflowStub (
645+ workflowClass ,
646+ WorkflowTargetOptions .newBuilder ().setWorkflowExecution (execution ).build ());
647+ return executeUpdate (
648+ options ,
649+ effective ->
650+ WorkflowClient .startUpdate (
651+ () -> updateMethod .apply (stub , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 ), effective ));
652+ }
620653}
0 commit comments