protected List <CustomJobFailedTarget> DeleteSuccessfulFailed(ExecutionFailures failures = null) { var failedTargets = failures?.Exceptions .Select(failure => new CustomJobFailedTarget { ID = failure.Key.ToString() }).ToList(); var retryTargets = GetRetryTargets(); var successfulRetryTargets = failedTargets == null ? retryTargets : retryTargets.Except(failedTargets, new CustomFailedJobComparer()).ToList(); foreach (var successfulTarget in successfulRetryTargets) { Log.Log($"Deleting successful target record '{successfulTarget.ID}' ..."); Service.Delete(CustomJobFailedTarget.EntityLogicalName, successfulTarget.Id); Log.Log($"Deleted successful target record '{successfulTarget.ID}'."); } var remainingFailures = failedTargets?.Except(successfulRetryTargets).ToList(); if (remainingFailures == null) { return(null); } // set the ID for the remaining failed targets' records // it was built on the fly without retrieve from CRM, so the IDs are empty foreach (var failure in remainingFailures) { var id = retryTargets.FirstOrDefault(retry => retry.ID == failure.ID)?.Id; if (id == null) { continue; } failure.Id = id.Value; } return(remainingFailures); }
protected List <CustomJobFailedTarget> AssociateFailedTargets(ExecutionFailures failures, Guid jobId) { var failedTargets = failures.Exceptions .Select(failure => new CustomJobFailedTarget { ID = jobId == failure.Key ? "No Target" : failure.Key.ToString(), CustomJob = jobId, FailureMessage = failure.Value.BuildExceptionMessage() }); var retryTargets = GetRetryTargets(); var newFailedTargets = failedTargets.Except(retryTargets, new CustomFailedJobComparer()).ToList(); foreach (var failedTarget in newFailedTargets) { Log.Log($"Creating failed target record for '{failedTarget.ID}' ..."); failedTarget.CustomJob = jobId; Service.Create(failedTarget); Log.Log($"Created failed target record for '{failedTarget.ID}'."); } return(newFailedTargets); }
protected override JobRunStatus ProcessFailure(ExecutionFailures executionResult) { AssociateFailedTargets(executionResult, Job.Id); DeleteSuccessfulFailed(executionResult); return(base.ProcessFailure(executionResult)); }
protected abstract JobRunStatus ProcessFailurePaging(ExecutionFailures failures, JobPagingInfo pagingInfo);