Exemplo n.º 1
0
        private void StopCampaignByScheduledDate(CoreCampaignSchema campaignSchema)
        {
            var campaignInfo = CampaignHelper.GetCampaignInfo(campaignSchema.EntityId);

            if (campaignInfo.CampaignStatusId == CampaignConsts.RunCampaignStatusId)
            {
                CampaignEventFacade.Finalize(_userConnection, campaignSchema);
                LogAction(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeStoppedBySchedule);
                CampaignEventFacade.Stop(_userConnection, campaignSchema);
            }
        }
 public CampaignConfigurationServiceResponse CompleteCampaignV2(Guid campaignId)
 {
     try {
         var campaignInfo = CampaignHelper.GetCampaignInfo(campaignId);
         if (campaignInfo.CampaignStatusId == CampaignConsts.StoppingCampaignStatusId ||
             campaignInfo.CampaignStatusId == CampaignConsts.CompletedCampaignStatusId)
         {
             string errorText = CampaignHelper
                                .GetLczStringValue(nameof(CampaignService), CampaignHasAlreadyStoppedException);
             string message = string.Format(errorText, campaignId);
             throw new InvalidOperationException(message);
         }
         var schema = CampaignHelper.GetCampaignSchema(campaignId);
         CampaignEventFacade.Finalize(UserConnection, schema);
         if (!campaignInfo.InProgress)
         {
             CampaignEventFacade.Stop(UserConnection, schema);
         }
     } catch (Exception e) {
         return(new CampaignConfigurationServiceResponse(e));
     }
     return(new CampaignConfigurationServiceResponse());
 }
Exemplo n.º 3
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);
 }