public void InitializeTest()
        {
            _mockSyncJobRepository          = new MockSyncJobRepository();
            _defaultRuntimeRetrievalService = new DefaultRuntimeRetrievalService(DEFAULT_RUNTIME_SECONDS);
            _mockLoggingRepository          = new MockLoggingRepository();

            _jobSchedulerConfig   = new JobSchedulerConfig(true, 0, true, false, START_TIME_DELAY_MINUTES, BUFFER_SECONDS, DEFAULT_RUNTIME_SECONDS);;
            _jobSchedulingService = new JobSchedulingService(
                _jobSchedulerConfig,
                _mockSyncJobRepository,
                _defaultRuntimeRetrievalService,
                _mockLoggingRepository
                );
        }
        public async Task ScheduleJobsWithConcurrency()
        {
            int defaultTenMinuteRuntime     = 600;
            var longerDefaultRuntimeService = new DefaultRuntimeRetrievalService(defaultTenMinuteRuntime);

            JobSchedulerConfig   jobSchedulerConfig   = new JobSchedulerConfig(true, 0, true, false, START_TIME_DELAY_MINUTES, BUFFER_SECONDS, DEFAULT_RUNTIME_SECONDS);;
            JobSchedulingService jobSchedulingService = new JobSchedulingService(
                jobSchedulerConfig,
                _mockSyncJobRepository,
                longerDefaultRuntimeService,
                _mockLoggingRepository
                );

            DateTime dateTimeNow         = DateTime.UtcNow.Date;
            List <SchedulerSyncJob> jobs = CreateSampleSyncJobs(10, 1, dateTimeNow.Date.AddDays(-20), dateTimeNow.Date);

            List <SchedulerSyncJob> updatedJobs = await jobSchedulingService.DistributeJobStartTimesAsync(jobs);

            jobs.Sort();
            updatedJobs.Sort();

            Assert.AreEqual(jobs.Count, updatedJobs.Count);
            Assert.AreEqual(jobs.Count, 10);

            // Check that times are sorted like this with concurrency of 2:
            // 0  2  4  6  8  9
            // 1  3  5  7
            for (int i = 0; i < jobs.Count; i++)
            {
                Assert.AreEqual(jobs[i].TargetOfficeGroupId, updatedJobs[i].TargetOfficeGroupId);
                Assert.IsTrue(jobs[i].StartDate < dateTimeNow);
                if (i < 8)
                {
                    Assert.IsTrue(updatedJobs[i].StartDate >= dateTimeNow.AddSeconds(60 * START_TIME_DELAY_MINUTES +
                                                                                     i / 2 * (defaultTenMinuteRuntime + BUFFER_SECONDS)));
                }
                else
                {
                    Assert.IsTrue(updatedJobs[i].StartDate >= dateTimeNow.AddSeconds(60 * START_TIME_DELAY_MINUTES +
                                                                                     (i - 5) * (defaultTenMinuteRuntime + BUFFER_SECONDS)));
                }
            }
        }
Ejemplo n.º 3
0
        private static async Task Main(string[] args)
        {
            var appSettings = AppSettings.LoadAppSettings();

            // Injections
            var logAnalyticsSecret = new LogAnalyticsSecret <LoggingRepository>(appSettings.LogAnalyticsCustomerId, appSettings.LogAnalyticsPrimarySharedKey, "JobScheduler");
            var loggingRepository  = new LoggingRepository(logAnalyticsSecret);
            var syncJobRepository  = new SyncJobRepository(appSettings.JobsStorageAccountConnectionString, appSettings.JobsTableName, loggingRepository);


            var telemetryConfiguration = new TelemetryConfiguration();

            telemetryConfiguration.InstrumentationKey = appSettings.APPINSIGHTS_INSTRUMENTATIONKEY;
            telemetryConfiguration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());

            IJobSchedulerConfig jobSchedulerConfig = new JobSchedulerConfig(
                appSettings.ResetJobs,
                appSettings.DaysToAddForReset,
                appSettings.DistributeJobs,
                appSettings.IncludeFutureJobs,
                appSettings.StartTimeDelayMinutes,
                appSettings.DelayBetweenSyncsSeconds,
                appSettings.DefaultRuntime);

            var runtimeRetrievalService = new DefaultRuntimeRetrievalService(jobSchedulerConfig.DefaultRuntimeSeconds);

            IJobSchedulingService jobSchedulingService = new JobSchedulingService(
                jobSchedulerConfig,
                syncJobRepository,
                runtimeRetrievalService,
                loggingRepository
                );

            IApplicationService applicationService = new ApplicationService(jobSchedulingService, jobSchedulerConfig, loggingRepository);

            // Call the JobScheduler ApplicationService
            await applicationService.RunAsync();
        }