protected override void OnStop() { CloseWebServiceHosts(); // stop the queue manager so that no new job instances are started JobQueueManager.Stop(); if (JobQueueManager.HasRunningJobs) { StringBuilder msg = new StringBuilder(); var runningJobs = JobQueueManager.RunningJobsByIntegrationId; msg.AppendLine("The Windows service is stopping. The following jobs will be completed first:"); foreach (var integrationName in runningJobs.Keys) { foreach (var jobInstance in runningJobs[integrationName]) { msg.AppendFormat("{0} : {1} : {2} ({3})", jobInstance.Integration.Name, jobInstance.Job.Name, jobInstance.SourceDataSource.DataSource.Name, jobInstance.Id); } } SyncEngineLogger.WriteToLog(LogEntryType.Info, msg.ToString()); } // continue to pause the service thread so long as jobs are running while (JobQueueManager.HasRunningJobs) { Thread.Sleep(1000); } }
public static void RefreshServiceConfig() { try { _serviceConfig = _configurator.GetServiceConfig(); JobQueueManager.Stop(); ConfigureMailNotifications(); if (!_serviceConfig.LogToDatabase) { SyncEngineLogger.DeregisterLogger(_databaseLogger); } if (!_serviceConfig.LogToFile) { SyncEngineLogger.DeregisterLogger(_textFileLogger); } JobQueueManager.Start(_serviceConfig.IntervalInSeconds); } catch (Exception ex) { EventViewerLogger.WriteToLog(ex); SyncEngineLogger.WriteExceptionToLog(ex); SyncEngineLogger.WriteToLog(LogEntryType.Warning, "The service config could not be refreshed and will occur the next time the service starts."); } }
private static void NotifyViaMail(Exception ex) { // if a MailException itself, exit to avoid an infinite loop if (ex is MailException || !EnableMailNotifications) { return; } if (mailNotifier == null) { WriteToLog(LogEntryType.Warning, "Email notifications are enabled but not configured. The email could not be sent."); return; } string msg = ""; Integration integration = null; JobInstance jobInstance = null; JobStepInstance jobStepInstance = null; try { // returns null if not found jobInstance = JobQueueManager.GetJobInstanceByParallelTaskId(Thread.CurrentThread.ManagedThreadId); if (jobInstance != null) { integration = jobInstance.Integration; jobStepInstance = jobInstance.RunningJobStepInstance; } var jobInfo = MailFormatter.GetFormattedJobInfoAsHtml(integration, jobInstance, jobStepInstance); msg = MailFormatter.GetTextAsFormattedDiv(jobInfo) + ExceptionFormatter.FormatExceptionForWeb(ex); } catch (Exception innerEx) { StringBuilder failureInfo = new StringBuilder(); failureInfo.AppendFormat("<b>Job info could not be obtained because of error:</b><br /> {0} {1}", innerEx.Message, innerEx.StackTrace); failureInfo.Append(HtmlBuilder.GetLineBreak(2)); msg = MailFormatter.GetTextAsFormattedDiv(failureInfo.ToString()) + ExceptionFormatter.FormatExceptionForWeb(ex); } // Exceptions are caught within MailNotifier class and logged via the SyncEngineLogger if (integration == null) { mailNotifier.SendMessage("SyncObjX Integration Services - An Error Has Occurred", msg); } else { mailNotifier.SendMessage(string.Format("SyncObjX Integration Services - Error Occurred in \"{0}\"", integration.Name), msg); } }
public override void Work() { bool flag = false; try { AppConfig appConfig; try { appConfig = new AppConfig(); } catch (ConfigurationErrorsException ex) { this.eventLog.LogEvent(MSExchangeJobQueueEventLogConstants.Tuple_FailedToLoadAppConfig, null, new object[] { ex.Message }); return; } TeamMailboxSyncConfiguration config = new TeamMailboxSyncConfiguration(appConfig.TMSyncCacheAbsoluteExpiry, appConfig.TMSyncCacheSlidingExpiry, appConfig.TMSyncCacheBucketCount, appConfig.TMSyncCacheBucketSize, appConfig.TMSyncMaxJobQueueLength, appConfig.TMSyncMaxPendingJobs, appConfig.TMSyncDispatcherWakeupInterval, appConfig.TMSyncMinSyncInterval, appConfig.TMSyncSharePointQueryPageSize, appConfig.TMSyncUseOAuth, appConfig.TMSyncHttpDebugEnabled); DocumentSyncJobQueue item = new DocumentSyncJobQueue(config, new TeamMailboxSyncResourceMonitorFactory(), new OAuthCredentialFactory(), true); MembershipSyncJobQueue item2 = new MembershipSyncJobQueue(config, new TeamMailboxSecurityRefresher(), new TeamMailboxSyncActiveDirectoryResourceMonitorFactory(), new OAuthCredentialFactory(), true); MaintenanceSyncJobQueue item3 = new MaintenanceSyncJobQueue(config, new TeamMailboxSyncActiveDirectoryResourceMonitorFactory(), new OAuthCredentialFactory(), true); PublicFolderSyncJobQueue item4 = new PublicFolderSyncJobQueue(); JobQueueManager.Initialize(new List <JobQueue> { item, item2, item3, item4 }); Exception ex2; if (!RpcServerWrapper.Start(appConfig.EnqueueRequestTimeout, out ex2)) { this.eventLog.LogEvent(MSExchangeJobQueueEventLogConstants.Tuple_FailedToRegisterRpc, null, new object[] { ex2.Message }); } else { flag = true; base.StopEvent.WaitOne(); } } finally { if (flag) { RpcServerWrapper.Stop(); JobQueueManager.Shutdown(); } } }
public SelfContainedMigrator(string migrationName, Guid migrationId, string sourceName, string targetName) { JobQueueManager.Start(1); _integration = new Integration(migrationId, migrationName, Assembly.GetCallingAssembly().Location, sourceName, targetName); var loggingPath = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + @"\Logs"; var textFileLogger = new TextFileLogger(loggingPath); SyncEngineLogger.RegisterLogger(textFileLogger, LoggingLevel.ErrorsWarningsInfoDebugAndTrace, -1); }
public TimeSpan GetMaxDelayedStartForJobPriority(JobPriority jobPriority) { try { return(JobQueueManager.GetMaxDelayedStartForJobPriority(jobPriority)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public void Stop() { try { JobQueueManager.Stop(); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public bool DequeueJob(Guid jobInstanceGuid) { try { return(JobQueueManager.DequeueJob(jobInstanceGuid)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public List <JobInstance> DequeueScheduledJobs() { try { return(JobQueueManager.DequeueScheduledJobs()); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public JobInstanceResult GetJobInstanceResult(Guid jobInstanceId) { try { return(JobQueueManager.GetJobInstanceResult(jobInstanceId)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public bool?QueueRequestIsComplete(Guid queueRequestId) { try { return(JobQueueManager.QueueRequestIsComplete(queueRequestId)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public void Start(double intervalInSeconds) { try { JobQueueManager.Start(intervalInSeconds); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public List <KeyValuePair <Guid, ConcurrentThreadState> > GetThreadUsagesByIntegrationId() { try { return(JobQueueManager.GetThreadUsagesByIntegrationId().ToList()); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public ConcurrentThreadState GetThreadUsage(Guid integrationId) { try { return(JobQueueManager.GetThreadUsage(integrationId)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public List <JobInstance> QueueJob(Integration integration, IEnumerable <DataSource> sourceSideDataSourcesToRun, Job jobToRun, DateTime scheduledStartTime, string invocationSource, JobInvocationSourceType invocationType) { try { return(JobQueueManager.QueueJob(integration, sourceSideDataSourcesToRun, jobToRun, scheduledStartTime, invocationSource, invocationType)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public JobInstance QueueJobWithFilters(Integration integration, DataSource sourceSideDataSourceToRun, Job jobToRun, DateTime scheduledStartTime, string invocationSource, JobInvocationSourceType invocationType, List <JobFilter> filters) { try { return(JobQueueManager.QueueJob(integration, sourceSideDataSourceToRun, jobToRun, scheduledStartTime, invocationSource, invocationType, filters)); } catch (Exception ex) { SyncEngineLogger.WriteExceptionToLog(ex, WEB_SERVICE_EXCEPTION_MESSAGE); throw; } }
public override byte[] EnqueueRequest(int version, int type, byte[] inputParameterBytes) { byte[] result; try { using (new Timer(new TimerCallback(RpcServerWrapper.CrashOnCallTimeout), Thread.CurrentThread, RpcServerWrapper.enqueueRequestTimeout, TimeSpan.FromMilliseconds(-1.0))) { EnqueueResult enqueueResult = JobQueueManager.Enqueue((QueueType)type, inputParameterBytes); EnqueueRequestRpcOutParameters enqueueRequestRpcOutParameters = new EnqueueRequestRpcOutParameters(enqueueResult); result = enqueueRequestRpcOutParameters.Serialize(); } } catch (Exception ex) { ExWatson.SendReport(ex, ReportOptions.None, null); EnqueueRequestRpcOutParameters enqueueRequestRpcOutParameters = new EnqueueRequestRpcOutParameters(new EnqueueResult(EnqueueResultType.UnexpectedServerError, ServerStrings.RpcServerUnhandledException(ex.Message))); result = enqueueRequestRpcOutParameters.Serialize(); } return(result); }
public void ExecuteJob(string jobName, JobTerminateOnErrorType jobTerminateOnErrorType, Type[] jobStepTypes) { var job = new Job(Guid.NewGuid(), jobName); job.TerminateOnErrorType = jobTerminateOnErrorType; job.AddDataSource(_sourceSideDataSource, SyncSide.Source); job.AddDataSource(_targetSideDataSource, SyncSide.Target); foreach (var jobStepType in jobStepTypes) { var jobStep = new JobStep(Guid.NewGuid(), jobStepType.Name, jobStepType.FullName); job.AddStep(jobStep); } JobQueueManager.QueueJob(_integration, _sourceSideDataSource, job, DateTime.Now, Path.GetFileName(Assembly.GetCallingAssembly().Location), JobInvocationSourceType.OnDemand); while (JobQueueManager.HasWaitingJobs || JobQueueManager.HasRunningJobs) { Thread.Sleep(500); } }
public static void WriteByParallelTaskContext(LogEntryType logEntryType, DataSource dataSource, Func <string> messageDelegate) { Integration integration = null; JobInstance jobInstance = null; JobStepInstance jobStepInstance = null; try { // returns null if not found jobInstance = JobQueueManager.GetJobInstanceByParallelTaskId(Thread.CurrentThread.ManagedThreadId); if (jobInstance != null) { integration = jobInstance.Integration; jobStepInstance = jobInstance.RunningJobStepInstance; } WriteToLog(logEntryType, integration, dataSource, jobInstance, jobStepInstance, messageDelegate); } catch (Exception ex) { WriteExceptionToLog(integration, dataSource, jobInstance, jobStepInstance, ex); } }
// Start the Windows service. protected override void OnStart(string[] onStartArgs) { try { // get connection string from connectionStrings in App.config GetIntegrationDbConnectionString(); // test connection to the queue database TestIntegrationDbConnection(IntegrationDbConnectionString); _dbQueueLogger = new JobQueueDatabaseLogger(IntegrationDbConnectionString); _configurator = new SyncEngineDatabaseConfigurator(IntegrationDbConnectionString); JobQueueManager.Configurator = _configurator; _serviceConfig = _configurator.GetServiceConfig(); // reset the logger as a precaution SyncEngineLogger.Clear(); // configure mail notifications, if enabled if (_serviceConfig.EnableMailNotifications) { ConfigureMailNotifications(); } // add database and text file loggers RegisterLoggers(); // register integrations for the database and text file loggers RegisterIntegrations(); // associate the database logger with the queue manager JobQueueLogManager.AddLogger(_dbQueueLogger); // recover any job instances from a server or service restart; this will only apply to on-demand job instances _dbQueueLogger.RecoverJobInstancesFromQueueLog(); // add the next run times for each scheduled job; clear any existing scheduled jobs from the queue _scheduledJobManager = new ScheduledJobManager(_configurator); _scheduledJobManager.QueueScheduledJobs(clearExistingScheduledJobInstancesFromWaitingQueue: true); // once a scheduled job is complete (i.e. queue request), queue for the next run time JobQueueManager.JobQueueRequestStatusChanged += new EventHandler <JobQueueRequestStatusChangedArgs>((s, e) => { if (e.QueueRequest.Status == JobQueueRequestStatus.Completed && e.QueueRequest.InvocationSourceType == JobInvocationSourceType.Scheduled) { _scheduledJobManager.QueueJobForNextScheduledRunTime(e.QueueRequest.Job.Id); } }); JobQueueManager.MaxDelayedStartByJobPriority = _configurator.GetJobPriorityConfig(); JobQueueManager.Start(_serviceConfig.IntervalInSeconds); InitializeWebServiceHosts(); } catch (Exception ex) { EventViewerLogger.WriteToLog(ex); SyncEngineLogger.WriteExceptionToLog(ex); // stop the service this.Stop(); } }