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); }
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); } }
/// <summary> /// Processes job for campaign action. /// <param name="userConnection">The user connection.</param> /// <param name="parameters">Job parameters.</param> /// </summary> public void Execute(UserConnection userConnection, IDictionary <string, object> parameters) { try { _userConnection = userConnection; var schemaUid = GetTypedParameter <Guid>("CampaignSchemaUId", parameters); var scheduledFireTime = GetTypedParameter <DateTime>("ScheduledUtcFireTime", parameters); var action = (CampaignScheduledAction)GetTypedParameter <int>("ScheduledAction", parameters); var schemaGeneratorStrategy = GetTypedParameter <CampaignSchemaExecutionStrategy>("SchemaGeneratorStrategy", parameters); var schemaManager = (CampaignSchemaManager)_userConnection.GetSchemaManager("CampaignSchemaManager"); CoreCampaignSchema campaignSchema = schemaManager.GetSchemaInstance(schemaUid); switch (action) { case CampaignScheduledAction.ScheduledStart: StartCampaign(campaignSchema, scheduledFireTime); break; case CampaignScheduledAction.Start: RunCampaign(campaignSchema, schemaGeneratorStrategy, scheduledFireTime); break; case CampaignScheduledAction.Run: RunCampaignWithInProgress(campaignSchema, schemaGeneratorStrategy, scheduledFireTime); break; case CampaignScheduledAction.Stop: CampaignEventFacade.Stop(_userConnection, campaignSchema); break; case CampaignScheduledAction.ScheduledStop: StopCampaignByScheduledDate(campaignSchema); break; default: break; } } catch (Exception ex) { string message = CampaignHelper.GetLczStringValue(nameof(CampaignJobExecutor), "ExecutionException"); Logger.Error(message, ex); throw; } }
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()); }
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); }