示例#1
0
        private bool TryScheduleNextJob(CoreCampaignSchema campaignSchema, DateTime?scheduledDate)
        {
            SetCampaignInProgress(campaignSchema.EntityId, false, scheduledDate);
            var jobConfig = CampaignTimeScheduler.GetNextFireTime(campaignSchema, scheduledDate);

            if (jobConfig.ScheduledAction == CampaignScheduledAction.Stop)
            {
                CampaignEventFacade.Stop(_userConnection, campaignSchema);
                return(false);
            }
            var latenessConfig = CampaignTimeScheduler.GetLatenessConfig(campaignSchema, jobConfig.Time);

            LogMisfiredRun(campaignSchema, latenessConfig, jobConfig.Time);
            if (latenessConfig.Lateness == CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements)
            {
                CampaignEventFacade.Stop(_userConnection, campaignSchema);
                return(false);
            }
            if (latenessConfig.Lateness == CampaignExecutionLateness.Critical ||
                latenessConfig.Lateness == CampaignExecutionLateness.MisfiredTimeConditionElements)
            {
                jobConfig = CampaignTimeScheduler.GetNextFireTime(campaignSchema, DateTime.UtcNow);
            }
            if (jobConfig.ScheduledAction != CampaignScheduledAction.ScheduledStop)
            {
                SetCampaignNextFireTime(campaignSchema.EntityId, jobConfig.Time);
            }
            CampaignJobDispatcher.ScheduleJob(campaignSchema, jobConfig);
            return(true);
        }
示例#2
0
 private void RunCampaign(CoreCampaignSchema campaignSchema,
                          CampaignSchemaExecutionStrategy schemaGeneratorStrategy, DateTime scheduledFireTime)
 {
     try {
         DateTime?stopDate       = GetScheduledStopDate(campaignSchema.EntityId);
         var      latenessConfig = CampaignTimeScheduler.GetLatenessConfig(campaignSchema, scheduledFireTime);
         LogMisfiredRun(campaignSchema, latenessConfig, scheduledFireTime);
         if (stopDate <= DateTime.UtcNow)
         {
             LogAction(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeStoppedBySchedule);
         }
         if (latenessConfig.Lateness == CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements ||
             stopDate <= DateTime.UtcNow)
         {
             CampaignEventFacade.Finalize(_userConnection, campaignSchema);
             CampaignEventFacade.Stop(_userConnection, campaignSchema);
             return;
         }
         if (latenessConfig.Lateness == CampaignExecutionLateness.NoMisfire)
         {
             campaignSchema.CampaignConfiguration["ScheduledUtcFireTime"] = scheduledFireTime;
             var config = new CampaignExecutionConfig {
                 CurrentFireTime   = scheduledFireTime,
                 ExecutionStrategy = schemaGeneratorStrategy
             };
             CampaignEngine.Run(campaignSchema, config);
         }
         else
         {
             scheduledFireTime = DateTime.UtcNow;
         }
     } catch (Exception e) {
         string message = CampaignHelper.GetLczStringValue(nameof(CampaignJobExecutor), "ExecutionException");
         Logger.Error(message, e);
     }
     TryScheduleNextJob(campaignSchema, scheduledFireTime);
 }