20
20
21
21
package io .temporal .internal .testservice ;
22
22
23
+ import static io .temporal .internal .testservice .LinkConverter .*;
23
24
import static io .temporal .internal .testservice .StateMachines .Action .CANCEL ;
24
25
import static io .temporal .internal .testservice .StateMachines .Action .COMPLETE ;
25
26
import static io .temporal .internal .testservice .StateMachines .Action .CONTINUE_AS_NEW ;
60
61
import io .temporal .api .failure .v1 .TimeoutFailureInfo ;
61
62
import io .temporal .api .history .v1 .*;
62
63
import io .temporal .api .nexus .v1 .*;
64
+ import io .temporal .api .nexus .v1 .Link ;
63
65
import io .temporal .api .protocol .v1 .Message ;
64
66
import io .temporal .api .query .v1 .WorkflowQueryResult ;
65
67
import io .temporal .api .taskqueue .v1 .StickyExecutionAttributes ;
@@ -347,11 +349,13 @@ static final class NexusOperationData {
347
349
RetryPolicy retryPolicy = defaultNexusRetryPolicy ();
348
350
349
351
long scheduledEventId = NO_EVENT_ID ;
352
+ Timestamp cancelRequestedTime ;
350
353
351
354
TestServiceRetryState retryState ;
352
- long lastAttemptCompleteTime ;
355
+ boolean isBackingOff = false ;
353
356
Duration nextBackoffInterval ;
354
- long nextAttemptScheduleTime ;
357
+ Timestamp lastAttemptCompleteTime ;
358
+ Timestamp nextAttemptScheduleTime ;
355
359
String identity ;
356
360
357
361
public NexusOperationData (Endpoint endpoint ) {
@@ -685,6 +689,18 @@ private static void scheduleNexusOperation(
685
689
NexusOperationRef ref = new NexusOperationRef (ctx .getExecutionId (), scheduledEventId );
686
690
NexusTaskToken taskToken = new NexusTaskToken (ref , data .getAttempt (), false );
687
691
692
+ Link link =
693
+ workflowEventToNexusLink (
694
+ io .temporal .api .common .v1 .Link .WorkflowEvent .newBuilder ()
695
+ .setNamespace (ctx .getNamespace ())
696
+ .setWorkflowId (ctx .getExecution ().getWorkflowId ())
697
+ .setRunId (ctx .getExecution ().getRunId ())
698
+ .setEventRef (
699
+ io .temporal .api .common .v1 .Link .WorkflowEvent .EventReference .newBuilder ()
700
+ .setEventId (scheduledEventId )
701
+ .setEventType (EventType .EVENT_TYPE_NEXUS_OPERATION_SCHEDULED ))
702
+ .build ());
703
+
688
704
PollNexusTaskQueueResponse .Builder pollResponse =
689
705
PollNexusTaskQueueResponse .newBuilder ()
690
706
.setTaskToken (taskToken .toBytes ())
@@ -697,6 +713,7 @@ private static void scheduleNexusOperation(
697
713
.setService (attr .getService ())
698
714
.setOperation (attr .getOperation ())
699
715
.setPayload (attr .getInput ())
716
+ .addLinks (link )
700
717
.setCallback ("http://test-env/operations" )
701
718
// The test server uses this to lookup the operation
702
719
.putCallbackHeader (
@@ -725,15 +742,24 @@ private static void startNexusOperation(
725
742
NexusOperationData data ,
726
743
StartOperationResponse .Async resp ,
727
744
long notUsed ) {
728
- ctx . addEvent (
745
+ HistoryEvent . Builder event =
729
746
HistoryEvent .newBuilder ()
730
747
.setEventType (EventType .EVENT_TYPE_NEXUS_OPERATION_STARTED )
731
748
.setNexusOperationStartedEventAttributes (
732
749
NexusOperationStartedEventAttributes .newBuilder ()
733
750
.setOperationId (resp .getOperationId ())
734
751
.setScheduledEventId (data .scheduledEventId )
735
- .setRequestId (data .scheduledEvent .getRequestId ()))
736
- .build ());
752
+ .setRequestId (data .scheduledEvent .getRequestId ()));
753
+
754
+ for (Link l : resp .getLinksList ()) {
755
+ if (!l .getType ()
756
+ .equals (io .temporal .api .common .v1 .Link .WorkflowEvent .getDescriptor ().getFullName ())) {
757
+ continue ;
758
+ }
759
+ event .addLinks (nexusLinkToWorkflowEvent (l ));
760
+ }
761
+
762
+ ctx .addEvent (event .build ());
737
763
ctx .onCommit (historySize -> data .operationId = resp .getOperationId ());
738
764
}
739
765
@@ -846,7 +872,10 @@ private static RetryState attemptNexusOperationRetry(
846
872
ctx .onCommit (
847
873
(historySize ) -> {
848
874
data .retryState = nextAttempt ;
849
- data .nextAttemptScheduleTime = ctx .currentTime ().getSeconds ();
875
+ data .isBackingOff = true ;
876
+ data .lastAttemptCompleteTime = ctx .currentTime ();
877
+ data .nextAttemptScheduleTime =
878
+ Timestamps .add (ProtobufTimeUtils .getCurrentProtoTime (), data .nextBackoffInterval );
850
879
task .setTaskToken (
851
880
new NexusTaskToken (
852
881
ctx .getExecutionId (),
@@ -899,7 +928,12 @@ private static void requestCancelNexusOperation(
899
928
// Test server only supports worker targets, so just push directly to Nexus task queue without
900
929
// invoking Nexus client.
901
930
ctx .addNexusTask (cancelTask );
902
- ctx .onCommit (historySize -> data .nexusTask = cancelTask );
931
+ ctx .onCommit (
932
+ historySize -> {
933
+ data .nexusTask = cancelTask ;
934
+ data .cancelRequestedTime = ctx .currentTime ();
935
+ data .isBackingOff = false ;
936
+ });
903
937
}
904
938
905
939
private static void reportNexusOperationCancellation (
@@ -1238,12 +1272,14 @@ private static void startWorkflow(
1238
1272
a .setParentWorkflowNamespace (parentExecutionId .getNamespace ());
1239
1273
a .setParentWorkflowExecution (parentExecutionId .getExecution ());
1240
1274
}
1241
- HistoryEvent event =
1275
+ HistoryEvent . Builder event =
1242
1276
HistoryEvent .newBuilder ()
1243
1277
.setEventType (EventType .EVENT_TYPE_WORKFLOW_EXECUTION_STARTED )
1244
- .setWorkflowExecutionStartedEventAttributes (a )
1245
- .build ();
1246
- ctx .addEvent (event );
1278
+ .setWorkflowExecutionStartedEventAttributes (a );
1279
+ if (request .getLinksCount () > 0 ) {
1280
+ event .addAllLinks (request .getLinksList ());
1281
+ }
1282
+ ctx .addEvent (event .build ());
1247
1283
}
1248
1284
1249
1285
private static void completeWorkflow (
0 commit comments