public void RunReports_ReportsRunningLessThanLimit_NewReportsRun()
        {
            // setup
            string            connName         = Guid.NewGuid().ToString();
            string            connectionString = Guid.NewGuid().ToString();
            ConnectionSetting conn             = new ConnectionSetting(connName, connectionString);

            _appSettings.MaxConcurrentReports.Returns(5);
            List <ReportJob> executingJobs = CreateReportJobList(2);

            _reportJobRepository.GetProcessingReports(conn.ConnectionString).Returns(executingJobs);

            List <ReportJob> returnValue = CreateReportJobList(3);

            _reportJobRepository.GetPendingReports(connectionString, 3, Arg.Any <IEnumerable <string> >()).Returns(returnValue);

            // execute
            var result = _reportCoordinator.RunReports(conn);

            // assert
            Assert.AreEqual(3, result.Count());

            // no call should have been made for more reports
            _reportJobRepository.Received(1).GetProcessingReports(conn.ConnectionString);
            _reportJobRepository.Received(1).GetPendingReports(connectionString, 3, Arg.Any <IEnumerable <string> >());
            _reportJobAgent.Received(3).ExecuteJobAsync(conn, Arg.Any <ReportJob>());
        }
示例#2
0
        public IEnumerable <ReportJob> RunReports(ConnectionSetting connection)
        {
            List <ReportJob> executedJobs = new List <ReportJob>();

            _logger.Debug("Retrieving unprocessed reports for connection {0}", connection.Name);

            // get the number of reports that are currently procesing for this connection
            List <ReportJob> executingReports = _reportJobRepository.GetProcessingReports(connection.ConnectionString).ToList();

            if (executingReports.Count >= _appSettings.MaxConcurrentReports)
            {
                _logger.Info("Maximum number of concurrent reports ({0}) are already being run for connection '{1}' exiting", _appSettings.MaxConcurrentReports, connection.Name);
                return(Enumerable.Empty <ReportJob>());
            }

            // extract the list of SingleExecutionGroups that are running
            List <string> singleExecutionGroups = executingReports.Where(x => !String.IsNullOrWhiteSpace(x.SingleExecutionGroup)).Select(x => x.SingleExecutionGroup).Distinct().ToList();

            _logger.Info("SingleExecutionGroup list to avoid [{0}]", String.Join(",", singleExecutionGroups));

            int reportsToRun = _appSettings.MaxConcurrentReports - executingReports.Count;

            _logger.Info("{0} reports executing for connection '{1}', checking queue for additional reports", executingReports.Count, connection.Name);
            IEnumerable <ReportJob> jobs = _reportJobRepository.GetPendingReports(connection.ConnectionString, reportsToRun, singleExecutionGroups);

            foreach (ReportJob job in jobs)
            {
                // if the job has a SingleExecutionGroup, we need to add it to the list so we are certain we don't run more
                // than one of these - we also need to check it hasn't already been added by a previous job retrieved in
                // the same call
                if (!String.IsNullOrWhiteSpace(job.SingleExecutionGroup))
                {
                    if (singleExecutionGroups.Contains(job.SingleExecutionGroup))
                    {
                        _logger.Info("Not running job '{0}' as a job with the same SingleExecutionGroup ('{1}') is already running", job.Id, job.SingleExecutionGroup);
                        continue;
                    }
                    else
                    {
                        singleExecutionGroups.Add(job.SingleExecutionGroup);
                        _logger.Info("Added SingleExecutionGroup '{0}' to list of groups to skip", job.SingleExecutionGroup);
                    }
                }

                _jobAgent.ExecuteJobAsync(connection, job);
                executedJobs.Add(job);
            }

            return(executedJobs);
        }
示例#3
0
 public void GetPendingReports_Executes_WithoutSqlErrors()
 {
     _reportJobRepository.GetPendingReports(TestUtility.TestDbConnectionString(TestUtility.TestRootFolder), 10, new List <string>());
 }