protected override TimeSpan CalculateDelay(NativeActivityContext context) { IParameters parameters = context.GetActivityContext().Parameters; TimeSpan delay = DelayVariable.Get(context); if (delay == default(TimeSpan)) { delay = DelayStartValue.Get(context) ?? parameters.DefaultRetryDelayStartValue; } else { TimeSpan delayMaxValue = DelayMaxValue.Get(context) ?? parameters.DefaultRetryDelayMaxValue; if (delay < delayMaxValue) { delay = TimeSpan.FromTicks((Int64)(delay.Ticks * (DelayMultiplicator.Get(context) ?? parameters.DefaultRetryDelayDelayMultiplicator))); if (delay > delayMaxValue) { delay = delayMaxValue; } } } DelayVariable.Set(context, delay); return(delay); }
protected void Execute<TTask>(NativeActivityContext context, CancellationTokenSource cts, TTask resultTask, Action<NativeActivityContext> postExecute) where TTask : Task { if (resultTask.IsCompleted) postExecute(context); else { IActivityContext activityContext = context.GetActivityContext(); taskCompletionNoPersistHandle.Get(context).Enter(context); cancellationTokenSource.Set(context, cts); Bookmark bookmark = context.CreateBookmark(BookmarkResumptionCallback); // continuations don't use cts, the main task is already completed, we can't cancel it resultTask .ContinueWith((_resultTask) => activityContext.ResumeBookmarkThroughHostAsync(bookmark, postExecute, TimeSpan.MaxValue), TaskContinuationOptions.ExecuteSynchronously).Unwrap() // TODO how to handle exception properly? // AsyncCodeActivity has an AsyncOperationContext and it can call Abort on that context directly, but we are left alone now, // we must schedule an Abort through the host, because NativeActivityContext is already disposed now .ContinueWith((_resumeBookmarkTask) => activityContext.AbortThroughHostAsync(_resumeBookmarkTask.Exception.InnerException), TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously).Unwrap() .ContinueWith((_abortWorkflowInstanceTask) => { var ignored = _abortWorkflowInstanceTask.Exception; }, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } }
protected override TimeSpan CalculateDelay(NativeActivityContext context) { var parameters = context.GetActivityContext().Parameters; var delay = this.DelayVariable.Get(context); if (delay == default) { delay = this.DelayStartValue.Get(context) ?? parameters.DefaultRetryDelayStartValue; } else { var delayMaxValue = this.DelayMaxValue.Get(context) ?? parameters.DefaultRetryDelayMaxValue; if (delay < delayMaxValue) { delay = TimeSpan.FromTicks((long)(delay.Ticks * (this.DelayMultiplicator.Get(context) ?? parameters.DefaultRetryDelayDelayMultiplicator))); if (delay > delayMaxValue) { delay = delayMaxValue; } } } this.DelayVariable.Set(context, delay); return(delay); }
private void SetTaskCompletionSourceResult(ReceiveRequestSendResponseScopeExecutionProperty <object> executionProperty, NativeActivityContext context) { executionProperty.SetTaskCompletionSourceResult(null, ThrowIfReloaded); if (context.GetActivityContext().TrackingEnabled) { context.Track(new SendResponseRecord()); } }
private void EvaluatorCompletionCallback(NativeActivityContext context, ActivityInstance completedInstance) { // The request's result delegate completed. if (completedInstance.State == ActivityInstanceState.Closed) { if (context.GetActivityContext().TrackingEnabled) { context.Track(new ReceiveResponseRecord()); } } }
private void EvaluatorCompletionCallback(NativeActivityContext context, ActivityInstance completedInstance) { // The receiving delegate completed. if (completedInstance.State == ActivityInstanceState.Closed) { if (context.GetActivityContext().TrackingEnabled) { context.Track(new ReceiveRequestRecord(this.OperationName)); } } }
// This will start/schedule the OnOperationAsync task, but won't wait for it, the task will be an implicit (single threaded reentrant) parallel activity. // The Scope is responsible to handle the outstanding task in case of Abort, Cancellation or Termination. protected override void Execute(NativeActivityContext context) { SendRequestReceiveResponseScopeExecutionProperty executionProperty = context.GetSendRequestReceiveResponseScopeExecutionProperty(); IActivityContext activityContext = context.GetActivityContext(); executionProperty.StartOnOperationAsync(activityContext, OperationName); if (activityContext.TrackingEnabled) { context.Track(new SendRequestRecord(OperationName)); } }
// We behave like an UnhandledException. protected override async Task <UnhandledExceptionAction> ExecuteAsync(NativeActivityContext context) { Exception propagatedException = PropagatedException.Get(context); IActivityContext activityContext = context.GetActivityContext(); UnhandledExceptionAction unhandledExceptionAction = activityContext.Parameters.UnhandledExceptionAction; if (unhandledExceptionAction != UnhandledExceptionAction.Abort && !await activityContext.NotifyHostOnUnhandledExceptionAsync(propagatedException, null)) { // If the host can't handle it, the instance will abort, independently from the configuration. unhandledExceptionAction = UnhandledExceptionAction.Abort; } return(unhandledExceptionAction); }
protected override TimeSpan CalculateDelay(NativeActivityContext context) { IParameters parameters = context.GetActivityContext().Parameters; TimeSpan delay = DelayVariable.Get(context); if (delay == default(TimeSpan)) delay = DelayStartValue.Get(context) ?? parameters.DefaultRetryDelayStartValue; else { TimeSpan delayMaxValue = DelayMaxValue.Get(context) ?? parameters.DefaultRetryDelayMaxValue; if (delay < delayMaxValue) { delay = TimeSpan.FromTicks((Int64)(delay.Ticks * (DelayMultiplicator.Get(context) ?? parameters.DefaultRetryDelayDelayMultiplicator))); if (delay > delayMaxValue) delay = delayMaxValue; } } DelayVariable.Set(context, delay); return delay; }
protected override TimeSpan CalculateDelay(NativeActivityContext context) => Expire.Get(context) + (Delay.Get(context) ?? context.GetActivityContext().Parameters.DefaultTimeoutDelay) - DateTime.UtcNow;
protected override TimeSpan CalculateDelay(NativeActivityContext context) => Expire.Get(context) + (Delay.Get(context) ?? context.GetActivityContext().Parameters.DefaultTimeoutDelay) - DateTime.UtcNow;