Пример #1
0
        private void PostRunActions(JobRunStatus runStatus)
        {
            if (runStatus.IsClose)
            {
                var finalStatus = runStatus.IsSuccess
                                        ? CustomJob.StatusReasonEnum.Success
                                        : CustomJob.StatusReasonEnum.Failure;

                Close(Service, finalStatus, Job.Id);
            }

            if (Job.DeleteOnSuccess == true &&
                runStatus.IsSuccess && runStatus.IsClose && runStatus.RunTargetFailures?.Any() != true)
            {
                log.Log("Checking target failures ...");
                var job = new CustomJob {
                    Id = Job.Id
                };
                job.LoadRelation(CustomJob.RelationNames.CustomJobFailedTargetsOfCustomJob, Service, false, 1);
                var isFailedExist = job.CustomJobFailedTargetsOfCustomJob?.Any() == true;
                log.Log($"Failed exist: {isFailedExist}.");

                if (!isFailedExist)
                {
                    log.Log("Deleting job ...");
                    Service.Delete(CustomJob.EntityLogicalName, Job.Id);
                    log.Log("Deleted job.");
                }
            }
        }
Пример #2
0
        private void LogRunStatus(JobRunStatus runStatus)
        {
            if (!runStatus.IsSuccess && runStatus.RunTargetFailures?.Any() == true)
            {
                runStatus.LatestRunMessage = "Failed run.\r\n\r\nFirst Exception: " +
                                             runStatus.RunTargetFailures.FirstOrDefault()?.FailureMessage;
            }
            else
            {
                runStatus.LatestRunMessage ??= (runStatus.IsSuccess ? "Successful run." : "Failed run.");
            }

            log.Log($"Updating latest run message: '{runStatus.LatestRunMessage}' ...",
                    runStatus.IsSuccess ? LogLevel.Info : LogLevel.Error);
            log.Log($"Updating latest date: '{Job.TargetDate ?? DateTime.UtcNow}' UTC ...");
            Service.Update(
                new CustomJob
            {
                Id = Job.Id,
                LatestRunMessage   = runStatus.LatestRunMessage,
                PreviousTargetDate = Job.TargetDate ?? DateTime.UtcNow
            });
            log.Log($"Updated latest run message.");
            log.Log($"Updated latest date.");

            if (Job.GenerateLogs == true && (!runStatus.IsSuccess || (runStatus.IsSuccess && Job.OnlyLogFailures != true)))
            {
                log.Log("Creating log entry ...");
                var logEntry =
                    new CustomJobLog
                {
                    Message              = DateTime.Now + ": " + (runStatus.IsSuccess ? "Successful run." : "Failed run."),
                    ExecutionDate        = Job.TargetDate ?? DateTime.UtcNow,
                    ExecutionFullMessage = runStatus.LatestRunMessage,
                    CustomJob            = Job.Id,
                    StatusReason         = runStatus.IsSuccess
                                                        ? CustomJobLog.StatusReasonEnum.Success
                                                        : CustomJobLog.StatusReasonEnum.Failure
                };

                if (runStatus.RunTargetFailures?.Any() == true)
                {
                    runStatus.RunTargetFailures.ForEach(failure => failure.CustomJob = null);
                    logEntry.CustomJobFailedTargetsOfLogEntry = runStatus.RunTargetFailures.ToArray();
                }

                Service.Create(logEntry);
                log.Log("Created log entry.");

                if (runStatus.ParentId.HasValue)
                {
                    logEntry.Message  += " [Sub-Job]";
                    logEntry.CustomJob = runStatus.ParentId.Value;
                    Service.Create(logEntry);
                    log.Log("Created log entry in parent.");
                }
            }
        }