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))); } } }
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(); }
public override void Configure(IFunctionsHostBuilder builder) { var keyVaultName = Environment.GetEnvironmentVariable("KeyVaultName"); var configService = new ConfigService(keyVaultName); configService.LoadConfigurationAsync().Wait(); var tableStorageAccount = CloudStorageAccount.Parse(configService.TableStorageAccountConnectionString); var tableClient = tableStorageAccount.CreateCloudTableClient(); var mediaServiceInstanceHealthTable = tableClient.GetTableReference(configService.MediaServiceInstanceHealthTableName); mediaServiceInstanceHealthTable.CreateIfNotExists(); var mediaServiceInstanceHealthTableStorageService = new TableStorageService(mediaServiceInstanceHealthTable); var jobOutputStatusTable = tableClient.GetTableReference(configService.JobOutputStatusTableName); jobOutputStatusTable.CreateIfNotExists(); var jobOutputStatusTableStorageService = new TableStorageService(jobOutputStatusTable); var mediaServiceCallHistoryTable = tableClient.GetTableReference(configService.MediaServiceCallHistoryTableName); mediaServiceCallHistoryTable.CreateIfNotExists(); var mediaServiceCallHistoryTableStorageService = new TableStorageService(mediaServiceCallHistoryTable); var jobVerificationRequestQueue = new QueueClient(configService.StorageAccountConnectionString, configService.JobVerificationRequestQueueName); jobVerificationRequestQueue.CreateIfNotExists(); var jobOutputStatusStorageService = new JobOutputStatusStorageService(jobOutputStatusTableStorageService); var mediaServiceCallHistoryStorageService = new MediaServiceCallHistoryStorageService(mediaServiceCallHistoryTableStorageService); var mediaServiceInstanceHealthStorageService = new MediaServiceInstanceHealthStorageService(mediaServiceInstanceHealthTableStorageService); var mediaServiceInstanceHealthService = new MediaServiceInstanceHealthService(mediaServiceInstanceHealthStorageService, jobOutputStatusStorageService, mediaServiceCallHistoryStorageService, configService); var jobVerificationRequestStorageService = new JobVerificationRequestStorageService(jobVerificationRequestQueue); var jobSchedulingService = new JobSchedulingService(mediaServiceInstanceHealthService, jobVerificationRequestStorageService, jobOutputStatusStorageService, new MediaServiceInstanceFactory(mediaServiceCallHistoryStorageService, configService), configService); builder.Services.AddSingleton <IJobSchedulingService>(jobSchedulingService); }