Exemplo n.º 1
0
        /// <summary>
        /// Returns config <see cref="CampaignExecutionLatenessConfig"/>, which describes lateness parameters.
        /// Lateness calculates relatively <paramref name="scheduledTime"/>.
        /// </summary>
        /// <param name="schema">Campaign's schema instance of
        /// <see cref="Terrasoft.Core.Campaign.CampaignSchema"/></param>
        /// <param name="scheduledTime">Time relatively this need calculate lateness config.</param>
        /// <returns>Returns instance <see cref="CampaignExecutionLatenessConfig"/>.</returns>
        public CampaignExecutionLatenessConfig GetLatenessConfig(CoreCampaignSchema schema, DateTime scheduledTime)
        {
            schema.CampaignConfiguration["ScheduledUtcFireTime"] = RoundToSeconds(scheduledTime);
            var latenessTime     = RoundToMinutes(CurrentTime - scheduledTime);
            var criticalLateness = schema.CriticalExecutionLateness;
            var latenessConfig   = new CampaignExecutionLatenessConfig {
                MisfiredTimeConditionElements = new List <CampaignSchemaElement>(),
                LatenessTime = latenessTime,
                Lateness     = CampaignExecutionLateness.NoMisfire
            };

            if (latenessTime.TotalMinutes <= 0)
            {
                return(latenessConfig);
            }
            var misfiredTimedElements = GetMisfiredTimedElements(schema, scheduledTime, CurrentTime);

            latenessConfig.MisfiredTimeConditionElements = misfiredTimedElements;
            if (latenessTime.TotalMinutes <= criticalLateness)
            {
                latenessConfig.Lateness = !misfiredTimedElements.Any()
                                        ? CampaignExecutionLateness.NoMisfire
                                        : CampaignExecutionLateness.MisfiredTimeConditionElements;
            }
            else
            {
                latenessConfig.Lateness = !misfiredTimedElements.Any()
                                        ? CampaignExecutionLateness.Critical
                                        : CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements;
            }
            return(latenessConfig);
        }
Exemplo n.º 2
0
        private void LogMisfiredRun(CoreCampaignSchema campaignSchema,
                                    CampaignExecutionLatenessConfig latenessConfig, DateTime scheduledDate)
        {
            string message;

            switch (latenessConfig.Lateness)
            {
            case CampaignExecutionLateness.MisfiredTimeConditionElements: {
                string errorText = CampaignHelper
                                   .GetLczStringValue(nameof(CampaignJobExecutor), "MisfiredTimeConditionElementError");
                message = string.Format(errorText, scheduledDate.ToString("g"),
                                        TimeSpanToString(latenessConfig.LatenessTime),
                                        GetElementsNames(latenessConfig.MisfiredTimeConditionElements));
                LogError(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeSkippedElement, message);
                break;
            }

            case CampaignExecutionLateness.Critical: {
                string errorText = CampaignHelper
                                   .GetLczStringValue(nameof(CampaignJobExecutor), "MisfiredCampaignExecutionError");
                message = string.Format(errorText, scheduledDate.ToString("g"),
                                        TimeSpanToString(latenessConfig.LatenessTime));
                LogError(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeSkippedRun, message);
                break;
            }

            case CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements: {
                string errorText = CampaignHelper
                                   .GetLczStringValue(nameof(CampaignJobExecutor), "CriticalExecutionLatenessError");
                message = string.Format(errorText, TimeSpanToString(latenessConfig.LatenessTime),
                                        TimeSpanToString(TimeSpan.FromMinutes(campaignSchema.CriticalExecutionLateness)),
                                        GetElementsNames(latenessConfig.MisfiredTimeConditionElements));
                LogError(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeCriticalLateness, message);
                string notificationText = CampaignHelper
                                          .GetLczStringValue(nameof(CampaignJobExecutor), "CriticalLatenessNotification");
                string notification = string.Format(notificationText, campaignSchema.Caption,
                                                    TimeSpanToString(TimeSpan.FromMinutes(campaignSchema.CriticalExecutionLateness)));
                CreateNotification(campaignSchema.EntityId, notification);
                break;
            }

            default:
                break;
            }
        }