protected override JobRunStatus ProcessFailurePaging(ExecutionFailures failures, JobPagingInfo pagingInfo)
        {
            var remainingFailed = DeleteSuccessfulFailed(failures);
            var status          = new JobRunStatus();

            if (IsNoRetry())
            {
                if (IsSubJob())
                {
                    var parentId = Job.ParentJob.Value;

                    AssociateFailedToParent(remainingFailed);

                    if (IsWaitingOnSubJobs(Service, parentId))
                    {
                        if (Job.IgnoreFailure == true)
                        {
                            Log.Log($"Updating paging info of job, page {pagingInfo.NextPage} ...");
                            UpdatePaging(Service, parentId, pagingInfo);
                            Log.Log($"Updated paging info of job, page {pagingInfo.NextPage}.");

                            Log.Log($"Updating status of job parent '{parentId}' to 'waiting' ...");
                            SetStatus(Service, CustomJob.StatusReasonEnum.Waiting, parentId, IsParentRecurrentJob());
                            Log.Log($"Updated status of job parent '{parentId}' to 'waiting'.");
                        }
                        else
                        {
                            Log.Log($"Updating status of job parent '{parentId}' to 'failed' ...");
                            Close(Service, CustomJob.StatusReasonEnum.Failure, Job.ParentJob.Value, true);
                            Log.Log($"Updated status of job parent '{parentId}' to 'failed'.");
                        }
                    }
                }

                status.IsClose = true;
            }
            else
            {
                if (Job.RetrySchedule != null)
                {
                    UpdateRetryTargetDate(Service, Job, Log);
                }

                IncrementRetry(Job.CurrentRetryRun ?? 0);

                Log.Log($"Updating status of job to 'retry' ...");
                SetStatus(Service, CustomJob.StatusReasonEnum.Retry, Job.Id, false);
                Log.Log($"Updated status of job 'retry'.");
            }

            status.IsSuccess        = false;
            status.LatestRunMessage = $"Retry run failed.";
            return(status);
        }
Example #2
0
        protected override JobRunStatus ProcessFailurePaging(ExecutionFailures failures, JobPagingInfo pagingInfo)
        {
            List <CustomJobFailedTarget> newFailures;
            var status = new JobRunStatus();

            if (IsNoRetry())
            {
                newFailures = AssociateFailedTargets(failures, Job.Id);

                if (Job.FailureAction != null)
                {
                    log.Log("Running failure action ...");

                    try
                    {
                        Service.Execute(
                            new ExecuteWorkflowRequest
                        {
                            EntityId   = Job.Id,
                            WorkflowId = Job.FailureAction.Value
                        });
                    }
                    catch (Exception exception)
                    {
                        log.Log(exception);
                    }

                    log.Log("Finished running failure action.");
                }

                if (Job.IgnoreFailure == true)
                {
                    status = ProcessSuccessPaging(pagingInfo);
                    status.RunTargetFailures = newFailures;

                    if (IsSubJob())
                    {
                        status.ParentId = Job.ParentJob.Value;
                    }

                    return(status);
                }

                if (IsSubJob())
                {
                    var parentId = Job.ParentJob.Value;

                    if (IsWaitingOnSubJobs(Service, parentId))
                    {
                        log.Log($"Updating status of job parent '{parentId}' to 'failed' ...");
                        Close(Service, CustomJob.StatusReasonEnum.Failure, parentId, true);
                        log.Log($"Updated status of job parent '{parentId}' to 'failed'.");
                    }

                    status.ParentId = parentId;
                }

                status.IsClose = true;
            }
            else
            {
                log.Log($"Creating a retry sub-job ...");
                var extendingJob = BuildSubJob(Job, CustomJob.StatusReasonEnum.Retry, $"Retry Page {Job.PageNumber ?? 1}");
                extendingJob.CurrentRetryRun = 1;
                extendingJob.Id = Service.Create(extendingJob);
                log.Log($"Created a retry sub-job '{extendingJob.Name}'.");

                newFailures = AssociateFailedTargets(failures, extendingJob.Id);

                log.Log($"Updating status of job 'waiting on subs' ...");
                SetStatus(Service, CustomJob.StatusReasonEnum.WaitingOnSubJobs, Job.Id, false);
                log.Log($"Updating status of job 'waiting on subs'.");
            }

            status.IsSuccess         = false;
            status.LatestRunMessage  = $"Page {Job.PageNumber} failed.";
            status.RunTargetFailures = newFailures;

            return(status);
        }