@@ -472,9 +472,6 @@ export class TransactionOrchestrator extends EventEmitter {
472
472
)
473
473
}
474
474
475
- const flow = transaction . getFlow ( )
476
- const options = TransactionOrchestrator . getWorkflowOptions ( flow . modelId )
477
-
478
475
if ( ! hasStepTimedOut ) {
479
476
step . changeStatus ( TransactionStepStatus . OK )
480
477
}
@@ -485,8 +482,15 @@ export class TransactionOrchestrator extends EventEmitter {
485
482
step . changeState ( TransactionStepState . DONE )
486
483
}
487
484
488
- if ( step . definition . async || options ?. storeExecution ) {
485
+ let shouldEmit = true
486
+ try {
489
487
await transaction . saveCheckpoint ( )
488
+ } catch ( error ) {
489
+ if ( SkipExecutionError . isSkipExecutionError ( error ) ) {
490
+ shouldEmit = false
491
+ } else {
492
+ throw error
493
+ }
490
494
}
491
495
492
496
const cleaningUp : Promise < unknown > [ ] = [ ]
@@ -499,10 +503,12 @@ export class TransactionOrchestrator extends EventEmitter {
499
503
500
504
await promiseAll ( cleaningUp )
501
505
502
- const eventName = step . isCompensating ( )
503
- ? DistributedTransactionEvent . COMPENSATE_STEP_SUCCESS
504
- : DistributedTransactionEvent . STEP_SUCCESS
505
- transaction . emit ( eventName , { step, transaction } )
506
+ if ( shouldEmit ) {
507
+ const eventName = step . isCompensating ( )
508
+ ? DistributedTransactionEvent . COMPENSATE_STEP_SUCCESS
509
+ : DistributedTransactionEvent . STEP_SUCCESS
510
+ transaction . emit ( eventName , { step, transaction } )
511
+ }
506
512
}
507
513
508
514
private static async skipStep (
@@ -605,7 +611,6 @@ export class TransactionOrchestrator extends EventEmitter {
605
611
}
606
612
607
613
const flow = transaction . getFlow ( )
608
- const options = TransactionOrchestrator . getWorkflowOptions ( flow . modelId )
609
614
610
615
const cleaningUp : Promise < unknown > [ ] = [ ]
611
616
@@ -654,8 +659,15 @@ export class TransactionOrchestrator extends EventEmitter {
654
659
}
655
660
}
656
661
657
- if ( step . definition . async || options ?. storeExecution ) {
662
+ let shouldEmit = true
663
+ try {
658
664
await transaction . saveCheckpoint ( )
665
+ } catch ( error ) {
666
+ if ( SkipExecutionError . isSkipExecutionError ( error ) ) {
667
+ shouldEmit = false
668
+ } else {
669
+ throw error
670
+ }
659
671
}
660
672
661
673
if ( step . hasRetryScheduled ( ) ) {
@@ -664,10 +676,12 @@ export class TransactionOrchestrator extends EventEmitter {
664
676
665
677
await promiseAll ( cleaningUp )
666
678
667
- const eventName = step . isCompensating ( )
668
- ? DistributedTransactionEvent . COMPENSATE_STEP_FAILURE
669
- : DistributedTransactionEvent . STEP_FAILURE
670
- transaction . emit ( eventName , { step, transaction } )
679
+ if ( shouldEmit ) {
680
+ const eventName = step . isCompensating ( )
681
+ ? DistributedTransactionEvent . COMPENSATE_STEP_FAILURE
682
+ : DistributedTransactionEvent . STEP_FAILURE
683
+ transaction . emit ( eventName , { step, transaction } )
684
+ }
671
685
}
672
686
673
687
private async executeNext (
@@ -696,17 +710,27 @@ export class TransactionOrchestrator extends EventEmitter {
696
710
continue
697
711
}
698
712
699
- console . log ( "Remaining STEPS" , nextSteps . remaining )
713
+ console . log (
714
+ "Remaining STEPS" ,
715
+ transaction . getFlow ( ) . modelId ,
716
+ nextSteps . remaining ,
717
+ nextSteps . next . map ( ( step ) => step . id ) ,
718
+ nextSteps . current ?? "nothing"
719
+ )
700
720
701
721
if ( nextSteps . remaining === 0 ) {
702
722
if ( transaction . hasTimeout ( ) ) {
703
723
void transaction . clearTransactionTimeout ( )
704
724
}
705
725
706
- await transaction . saveCheckpoint ( )
726
+ // let shouldStop = false
727
+ // await transaction.saveCheckpoint()
707
728
708
729
console . log ( "FINISH" , transaction . getFlow ( ) . transactionId )
709
730
this . emit ( DistributedTransactionEvent . FINISH , { transaction } )
731
+ // if (shouldStop) {
732
+ // return
733
+ // }
710
734
}
711
735
712
736
let hasSyncSteps = false
@@ -827,14 +851,15 @@ export class TransactionOrchestrator extends EventEmitter {
827
851
] as Parameters < TransactionStepHandler >
828
852
829
853
if ( ! isAsync ) {
830
- try {
831
- await transaction . saveCheckpoint ( )
832
- } catch ( error ) {
833
- if ( SkipExecutionError . isSkipExecutionError ( error ) ) {
834
- continueExecution = false
835
- continue
836
- }
837
- }
854
+ // try {
855
+ // await transaction.saveCheckpoint()
856
+ // } catch (error) {
857
+ // if (SkipExecutionError.isSkipExecutionError(error)) {
858
+ // await transaction.clearStepTimeout(step)
859
+ // continueExecution = false
860
+ // continue
861
+ // }
862
+ // }
838
863
839
864
hasSyncSteps = true
840
865
@@ -873,8 +898,8 @@ export class TransactionOrchestrator extends EventEmitter {
873
898
)
874
899
} )
875
900
. catch ( async ( error ) => {
876
- console . log ( "ON Failure SYNC" , error )
877
901
if ( SkipExecutionError . isSkipExecutionError ( error ) ) {
902
+ await transaction . clearStepTimeout ( step )
878
903
continueExecution = false
879
904
return
880
905
}
@@ -963,6 +988,7 @@ export class TransactionOrchestrator extends EventEmitter {
963
988
console . log ( "ON Failure" , error )
964
989
965
990
if ( SkipExecutionError . isSkipExecutionError ( error ) ) {
991
+ await transaction . clearStepTimeout ( step )
966
992
continueExecution = false
967
993
return
968
994
}
0 commit comments