/// <summary> /// Executes the specified plugin execution method, handling retries as configured in the <see cref="PluginExecutionData" />. /// </summary> /// <param name="action">The plugin method to execute.</param> /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns> public PluginExecutionResult Run(Func <PluginExecutionResult> action) { PluginExecutionResult executionResult = InvokeAction(action); PluginRetryAction retryAction = GetRetryAction(executionResult.Result); // Only retry if the action specifies we should AND the action did not already while (retryAction == PluginRetryAction.Retry && executionResult.RetryStatus == PluginRetryStatus.DidNotRetry) { PluginResult currentResult = executionResult.Result; OnStatusMessageUpdate($"Retry triggered for state {currentResult})."); _retryCounts.Increment(currentResult); LogRetryData(executionResult); DelayBeforeRetry(_executionData.RetrySettings[currentResult]); OnStatusMessageUpdate($"Starting retry number {TotalRetries}."); executionResult = InvokeAction(action); retryAction = GetRetryAction(executionResult.Result); } // Update the retry status if it is still set to "did not retry" if (executionResult.RetryStatus == PluginRetryStatus.DidNotRetry) { // Determine the final retry status based on the specified retry action switch (retryAction) { case PluginRetryAction.Halt: OnStatusMessageUpdate("Halting execution per retry settings."); executionResult.RetryStatus = PluginRetryStatus.Halt; break; case PluginRetryAction.Continue: default: executionResult.RetryStatus = PluginRetryStatus.Continue; break; } } return(executionResult); }
private void LogRetryData(PluginExecutionResult result) { ExecutionServices.DataLogger.Submit(new ActivityRetryLog(_executionData, result)); }