Example #1
0
        public void MonitorFactoryReturnsABadFileMonitorerWhenItShould()
        {
            var result = _monitorFactory.GetMonitorer(new MonitorJob
            {
                MontiredJobType = MontiredJobType.BadFileDirectory
            });

            Assert.That(result is BadFilesFolderMonitorer);
        }
Example #2
0
        void ThreadStart()
        {
            Log.DebugFormat("Stepped into ThreadStart");
            var waitHandles = new WaitHandle[] { _manualResetEvent };

            _theServiceShouldContinue = true;

            var monitorJobSet = _dataActions.GetAllCurrentMonitorJobsForThisServer(Environment.MachineName);

            Log.DebugFormat("Threadstart found '{0}' jobs to run currently", monitorJobSet.MonitorJobs.Count);

            while (_theServiceShouldContinue)
            {
                try
                {
                    Log.DebugFormat("Looping");
                    if (_theServiceShouldContinue && _monitorJobActions.WeAreInTheRunWindow())
                    {
                        if (_monitorJobActions.JobsetHasExpired(monitorJobSet))
                        {
                            monitorJobSet = _dataActions.GetAllCurrentMonitorJobsForThisServer(Environment.MachineName);
                            Log.DebugFormat("Threadstart found '{0}' jobs to run currently", monitorJobSet.MonitorJobs.Count);
                        }

                        foreach (var monitorJob in monitorJobSet.MonitorJobs)
                        {
                            if (_monitorJobActions.ThisJobShouldRunNow(monitorJob))
                            {
                                var monitorer = _monitorFactory.GetMonitorer(monitorJob);
                                monitorer.Process(monitorJob);
                            }
                        }
                    }

                    if (WaitHandle.WaitAny(waitHandles, TimeSpan.FromSeconds(_applicationSettings.RetryIntervalInSeconds), false) != WaitHandle.WaitTimeout)
                    {
                        _theServiceShouldContinue = false;
                    }
                }
                catch (SqlException sqlEx)
                {
                    Log.ErrorFormat("ThreadStart caught a SqlException, database may be down, the exception was '{0}'", sqlEx);
                    //Do not throw here or the service will stop and we certainly do not want that.
                    if (WaitHandle.WaitAny(waitHandles, TimeSpan.FromMinutes(_applicationSettings.RetryIntervalInSeconds), false) != WaitHandle.WaitTimeout)
                    {
                        _theServiceShouldContinue = false;
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("ThreadStart threw the error '{0}'", ex);
                    //Do not throw here or the service will stop and we certainly do not want that.
                    if (WaitHandle.WaitAny(waitHandles, TimeSpan.FromMinutes(_applicationSettings.RetryIntervalInSeconds), false) != WaitHandle.WaitTimeout)
                    {
                        _theServiceShouldContinue = false;
                    }
                }
            }
        }