@@ -100,7 +100,7 @@ public async Task ExecuteAsync()
100100 }
101101 else
102102 {
103- act . Cancel ( task . Cancel . Reason ) ;
103+ act . Cancel ( task . Cancel ) ;
104104 }
105105 break ;
106106 case null :
@@ -422,10 +422,23 @@ await Task.WhenAll(tsk.Start.Input.Select(p =>
422422 act . Context . Info . ActivityType ) ;
423423 completion . Result . WillCompleteAsync = new ( ) ;
424424 }
425+ catch ( OperationCanceledException e ) when (
426+ act . ServerRequestedCancel && act . Context . CancellationDetails ? . IsPaused == true )
427+ {
428+ act . Context . Logger . LogDebug (
429+ "Completing activity {ActivityType} as failed due cancel exception caused by pause" ,
430+ act . Context . Info . ActivityType ) ;
431+ completion . Result . Failed = new ( )
432+ {
433+ Failure_ = await dataConverter . ToFailureAsync (
434+ new ApplicationFailureException (
435+ "Activity paused" , e , "ActivityPause" ) ) . ConfigureAwait ( false ) ,
436+ } ;
437+ }
425438 catch ( OperationCanceledException ) when ( act . ServerRequestedCancel )
426439 {
427440 act . Context . Logger . LogDebug (
428- "Completing activity {ActivityType} as cancelled" ,
441+ "Completing activity {ActivityType} as cancelled, reason: " ,
429442 act . Context . Info . ActivityType ) ;
430443 completion . Result . Cancelled = new ( )
431444 {
@@ -557,7 +570,8 @@ public void MarkDone()
557570 /// Cancel this activity for the given reason if not already cancelled.
558571 /// </summary>
559572 /// <param name="reason">Cancel reason.</param>
560- public void Cancel ( ActivityCancelReason reason )
573+ /// <param name="details">Cancellation details.</param>
574+ public void Cancel ( ActivityCancelReason reason , ActivityCancellationDetails details )
561575 {
562576 // Ignore if already cancelled
563577 if ( cancelTokenSource . IsCancellationRequested )
@@ -570,37 +584,49 @@ public void Cancel(ActivityCancelReason reason)
570584 "Cancelling activity {TaskToken}, reason {Reason}" ,
571585 Context . TaskToken ,
572586 reason ) ;
573- Context . CancelReasonRef . CancelReason = reason ;
587+ Context . CancelRef . CancelReason = reason ;
588+ Context . CancelRef . CancellationDetails = details ;
574589 cancelTokenSource . Cancel ( ) ;
575590 }
576591 }
577592
578593 /// <summary>
579- /// Cancel this activity for the given upstream reason .
594+ /// Cancel this activity with the given upstream info .
580595 /// </summary>
581- /// <param name="reason ">Cancel reason .</param>
582- public void Cancel ( Bridge . Api . ActivityTask . ActivityCancelReason reason )
596+ /// <param name="cancel ">Cancel.</param>
597+ public void Cancel ( Bridge . Api . ActivityTask . Cancel cancel )
583598 {
584599 lock ( mutex )
585600 {
586601 serverRequestedCancel = true ;
587602 }
588- switch ( reason )
603+ var details = new ActivityCancellationDetails ( )
604+ {
605+ IsGoneFromServer = cancel . Details ? . IsNotFound ?? false ,
606+ IsCancelRequested = cancel . Details ? . IsCancelled ?? false ,
607+ IsTimedOut = cancel . Details ? . IsTimedOut ?? false ,
608+ IsWorkerShutdown = cancel . Details ? . IsWorkerShutdown ?? false ,
609+ IsPaused = cancel . Details ? . IsPaused ?? false ,
610+ } ;
611+ switch ( cancel . Reason )
589612 {
590613 case Bridge . Api . ActivityTask . ActivityCancelReason . NotFound :
591- Cancel ( ActivityCancelReason . GoneFromServer ) ;
614+ Cancel ( ActivityCancelReason . GoneFromServer , details ) ;
592615 break ;
593616 case Bridge . Api . ActivityTask . ActivityCancelReason . Cancelled :
594- Cancel ( ActivityCancelReason . CancelRequested ) ;
617+ Cancel ( ActivityCancelReason . CancelRequested , details ) ;
595618 break ;
596619 case Bridge . Api . ActivityTask . ActivityCancelReason . TimedOut :
597- Cancel ( ActivityCancelReason . Timeout ) ;
620+ Cancel ( ActivityCancelReason . Timeout , details ) ;
598621 break ;
599622 case Bridge . Api . ActivityTask . ActivityCancelReason . WorkerShutdown :
600- Cancel ( ActivityCancelReason . WorkerShutdown ) ;
623+ Cancel ( ActivityCancelReason . WorkerShutdown , details ) ;
624+ break ;
625+ case Bridge . Api . ActivityTask . ActivityCancelReason . Paused :
626+ Cancel ( ActivityCancelReason . Paused , details ) ;
601627 break ;
602628 default :
603- Cancel ( ActivityCancelReason . None ) ;
629+ Cancel ( ActivityCancelReason . None , details ) ;
604630 break ;
605631 }
606632 }
@@ -702,7 +728,9 @@ private async Task HeartbeatAsync(TemporalWorker worker)
702728 Context . Logger . LogWarning (
703729 e , "Cancelling activity because failed recording heartbeat" ) ;
704730 }
705- Cancel ( ActivityCancelReason . HeartbeatRecordFailure ) ;
731+ Cancel (
732+ ActivityCancelReason . HeartbeatRecordFailure ,
733+ new ( ) { IsHeartbeatRecordFailure = true } ) ;
706734 }
707735 }
708736 }
0 commit comments