public void TestConfigurationChangeNoChanges() { SchedulerConfiguration current = SchedulerConfiguration.Active; try { ISchedule oneOff = Scheduler.GetSchedule("OneOff"); ISchedule gap = Scheduler.GetSchedule("Gap"); ISchedule etm = Scheduler.GetSchedule("EveryTwoMonths"); ISchedule aggregate = Scheduler.GetSchedule("Aggregate"); bool enabled = Scheduler.Enabled; Duration defaultMaxDuration = Scheduler.DefaultMaximumDuration; int defaultMaxHistory = Scheduler.DefaultMaximumHistory; SchedulerConfiguration.Active = CloneConfig(current); Thread.Sleep(ConfigurationExtensions.EventBufferMs * 2); Assert.AreSame(oneOff, Scheduler.GetSchedule("OneOff")); Assert.AreSame(gap, Scheduler.GetSchedule("Gap")); Assert.AreSame(etm, Scheduler.GetSchedule("EveryTwoMonths")); Assert.AreSame(aggregate, Scheduler.GetSchedule("Aggregate")); Assert.AreEqual(Scheduler.Enabled, enabled); Assert.AreEqual(Scheduler.DefaultMaximumDuration, defaultMaxDuration); Assert.AreEqual(Scheduler.DefaultMaximumHistory, defaultMaxHistory); } finally { SchedulerConfiguration.Active = current; } }
public void TestConfigurationChangeEnabled() { SchedulerConfiguration current = SchedulerConfiguration.Active; try { ISchedule oneOff = Scheduler.GetSchedule("OneOff"); ISchedule gap = Scheduler.GetSchedule("Gap"); ISchedule etm = Scheduler.GetSchedule("EveryTwoMonths"); ISchedule aggregate = Scheduler.GetSchedule("Aggregate"); Assert.AreEqual(Scheduler.Enabled, true); SchedulerConfiguration newConfig = CloneConfig(current); newConfig.Enabled = false; SchedulerConfiguration.Active = newConfig; Thread.Sleep(ConfigurationExtensions.EventBufferMs * 2); Assert.AreEqual(Scheduler.Enabled, false); Assert.AreSame(oneOff, Scheduler.GetSchedule("OneOff")); Assert.AreSame(gap, Scheduler.GetSchedule("Gap")); Assert.AreSame(etm, Scheduler.GetSchedule("EveryTwoMonths")); Assert.AreSame(aggregate, Scheduler.GetSchedule("Aggregate")); } finally { SchedulerConfiguration.Active = current; } }
public SchedulingService(Logger logger, SchedulerConfiguration schedulerConfig, IMapper mapper) { Log.Logger = logger; _mapper = mapper; var services = new ServiceCollection(); services.AddTransient(s => logger); services.AddTransient(s => schedulerConfig); services.AddTransient <SqlScramblingJob>(); services.AddTransient <MySqlScramblingJob>(); var container = services.BuildServiceProvider(); var jobFactory = new ScramblerJobFactory(container); var schedulerFactory = new StdSchedulerFactory(schedulerConfig.NameValueCollection); var scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult(); scheduler.JobFactory = jobFactory; _scheduler = scheduler; //_scheduler.Start(); }
/// <summary> /// Loads the configuration. /// </summary> internal static void LoadConfiguration() { SchedulerConfiguration schedulerConfiguration = SchedulerConfiguration.Active; Debug.Assert(schedulerConfiguration != null); DefaultMaximumHistory = schedulerConfiguration.DefautlMaximumHistory; DefaultMaximumDuration = schedulerConfiguration.DefaultMaximumDuration; // Get the names of the schedules that were last loaded from the configuration HashSet <string> current = new HashSet <string>( _schedules.Values.Where(s => s.IsFromConfiguration).Select(s => s.Schedule.Name)); foreach (ScheduleElement scheduleElement in schedulerConfiguration.Schedules) { ISchedule schedule = AddSchedule(scheduleElement.GetInstance <ISchedule>(), true); // Remove the names of schedules that are in the config current.Remove(schedule.Name); } // Any schedules left should be removed. foreach (string name in current) { Debug.Assert(name != null); RemoveSchedule(name); } Enabled = schedulerConfiguration.Enabled; }
public void TestConfigurationChangeAggregate() { SchedulerConfiguration current = SchedulerConfiguration.Active; try { ISchedule oneOff = Scheduler.GetSchedule("OneOff"); ISchedule gap = Scheduler.GetSchedule("Gap"); ISchedule etm = Scheduler.GetSchedule("EveryTwoMonths"); ISchedule aggregate = Scheduler.GetSchedule("Aggregate"); SchedulerConfiguration newConfig = CloneConfig(current); newConfig.Schedules["Aggregate"].Parameters.Remove("schedule3"); SchedulerConfiguration.Active = newConfig; Thread.Sleep(ConfigurationExtensions.EventBufferMs * 2); Assert.AreSame(oneOff, Scheduler.GetSchedule("OneOff")); Assert.AreSame(gap, Scheduler.GetSchedule("Gap")); Assert.AreSame(etm, Scheduler.GetSchedule("EveryTwoMonths")); AggregateSchedule newAggregate = Scheduler.GetSchedule("Aggregate") as AggregateSchedule; Assert.IsNotNull(newAggregate); Assert.AreNotSame(aggregate, newAggregate); Assert.AreEqual(2, newAggregate.Count()); } finally { SchedulerConfiguration.Active = current; } }
public FileScheduler(SchedulerConfiguration configuration, ILoggerFacade logger) : base(configuration, logger) { if (this.logger != null) { this.logger.Log("FileScheduler is created.", Category.Info, Priority.High); } }
public SchedulerCollectorConfigurationService(SchedulerConfiguration schedulerConfiguration, ISchedulerCollectorConfigurationReadService collectorConfigurationReadService, ISchedulerCollectorConfigurationWatcher configurationWatcher ) { _schedulerConfiguration = schedulerConfiguration; _collectorConfigurationReadService = collectorConfigurationReadService; _configurationWatcher = configurationWatcher; }
public void It_should_build_a_SchedulerConfiguration() { var sut = new SchedulerConfiguration() { Cron = "* * * * * *" }; Assert.AreEqual("* * * * * *", sut.Cron); }
private SchedulerConfiguration CloneConfig([NotNull] SchedulerConfiguration config) { return(new SchedulerConfiguration { DefaultMaximumDuration = config.DefaultMaximumDuration, DefautlMaximumHistory = config.DefautlMaximumHistory, Enabled = config.Enabled, Schedules = CloneCollection(config.Schedules) }); }
public SchedulerBase(SchedulerConfiguration configuration, ILoggerFacade logger) { this.mediums = new List<ICacheMedium>(); this.logger = logger; this.CreateCacheHierarchy(configuration.MediumSizeList); this.UpdateReplacementAlgorithms(configuration); this.HookEvents(); }
public ICacheScheduler Create(SchedulerConfiguration configuration, ILoggerFacade logger) { switch (configuration.Type) { case SchedulerType.RAMScheduler: return new RAMScheduler(configuration, logger); case SchedulerType.FileScheduler: return new FileScheduler(configuration, logger); case SchedulerType.RAMFileScheduler: return new RAMFileScheduler(configuration, logger); default: throw new NotSupportedException("Not support scheduler"); } }
public CollectorConfig LoadSchedulerConfiguration(SchedulerConfiguration schedulerConfiguration) { switch (schedulerConfiguration?.CollectorConfigProvider) { case CollectorConfigProvider.File: return(LoadCollectorConfigFromFile(schedulerConfiguration.CollectorConfigFileName)); case CollectorConfigProvider.Database: return(LoadCollectorConfigFromDatabase(schedulerConfiguration.SchedulerAgentId)); default: throw new NotImplementedException(); } }
static void Main(string[] args) { var config = new ConfigurationBuilder() .AddSchedulerConfig() .Build(); var serviceProvider = new ServiceCollection() .ConfigureSchedulerConfig(config) .BuildServiceProvider(); Configuration = serviceProvider.GetSchedulerConfig(); System.Console.WriteLine(); System.Console.ReadLine(); }
public void BeginCollectorConfigurationChangePolling(SchedulerConfiguration compareConfiguration, CollectorConfig compareCollectorConfig) { _compareCollectorConfig = compareCollectorConfig; _compareConfiguration = compareConfiguration; if (_compareConfiguration.CollectorPollingInterval < MinimumPollingInterval) { // Log this away or throw exception return; } Observable.Timer(_compareConfiguration.CollectorPollingInterval, _compareConfiguration.CollectorPollingInterval) .TakeUntil(_stopTimer) .Subscribe(_ => PollConfigurationForChanges()); }
public void TestConfigurationChangeGap() { SchedulerConfiguration current = SchedulerConfiguration.Active; try { ISchedule oneOff = Scheduler.GetSchedule("OneOff"); ISchedule gap = Scheduler.GetSchedule("Gap"); ISchedule etm = Scheduler.GetSchedule("EveryTwoMonths"); ISchedule aggregate = Scheduler.GetSchedule("Aggregate"); SchedulerConfiguration newConfig = CloneConfig(current); newConfig.Schedules["Gap"].Parameters["timeSpan"].Value = "4.00:00:00"; SchedulerConfiguration.Active = newConfig; Thread.Sleep(ConfigurationExtensions.EventBufferMs * 2); Assert.AreSame(oneOff, Scheduler.GetSchedule("OneOff")); Assert.AreNotSame(gap, Scheduler.GetSchedule("Gap")); Assert.AreSame(etm, Scheduler.GetSchedule("EveryTwoMonths")); Assert.AreNotSame(aggregate, Scheduler.GetSchedule("Aggregate")); ISchedule newGap = Scheduler.GetSchedule("Gap"); Assert.IsNotNull(newGap); Assert.IsInstanceOfType(newGap, typeof(GapSchedule)); Instant i = Instant.FromDateTimeOffset(DateTimeOffset.Parse("13/01/2100 09:10:11 +00:00")); Duration d = Duration.FromTimeSpan(TimeSpan.Parse("4.00:00:00")); Assert.AreEqual(i + d, newGap.Next(i)); AggregateSchedule newAggregate = Scheduler.GetSchedule("Aggregate") as AggregateSchedule; Assert.IsNotNull(newAggregate); ISchedule[] array = newAggregate.ToArray(); Assert.AreEqual(3, array.Length); Assert.AreSame(oneOff, array[0]); Assert.AreSame(newGap, array[1]); Assert.AreSame(etm, array[2]); } finally { SchedulerConfiguration.Active = current; } }
public ReFreshThread() { Timer t = new Timer(300000); t.Elapsed += new ElapsedEventHandler(ReFreshThread2); t.AutoReset = true; t.Enabled = true; //实例化调度配置 SchedulerConfiguration config = new SchedulerConfiguration(1000 * 60 * 60); //一小时刷新一次 //添加任务 config.Jobs.Add(new SchedulerJob()); Scheduler scheduler = new Scheduler(config); //创建 ThreadStart 委托 System.Threading.ThreadStart myThreadStart = new System.Threading.ThreadStart(scheduler.Start); //实例化线程 schedulerThread = new System.Threading.Thread(myThreadStart); //启动线程 schedulerThread.Start(); }
public void Adjust(SchedulerConfiguration configuration) { if (this.logger != null) { this.logger.Log("Adjust scheduler configuration.", Category.Info, Priority.High); } this.UpdateReplacementAlgorithms(configuration); }
private void UpdateReplacementAlgorithms(SchedulerConfiguration configuration) { this.ValidateReplacementAlgorithm(configuration.Algorithms); for(int i = 0; i < this.mediums.Count; ++i) { this.mediums[i].ReplacementAlgorithm = configuration.Algorithms[i]; } }
private static SchedulerConfiguration GenerateConfigForScheduler() { var schedulerConfig = new SchedulerConfiguration { Percentile = 80, Timeframe = new TimeSpan(2, 0, 0), RescheduleInterval = new TimeSpan(0, 10, 0), ExecuteInterval = new TimeSpan(0, 0, 1), ExecutionStatisticsRefreshInterval = new TimeSpan(23, 59, 0) }; // create service configuration var serviceList = new List <ServiceConfiguration> { new ServiceConfiguration() { IsEnabled = true, ServiceName = "Dummy", ServiceClass = typeof(DummyService).AssemblyQualifiedName, HostName = "Johnny" } }; // add scheduling rule to service config serviceList[0].SchedulingRules.Add(new SchedulingRule { Scope = SchedulingScope.Day, Times = new TimeSpan[] { new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) }, MaxDeviationBefore = new TimeSpan(0, 0, 0), MaxDeviationAfter = new TimeSpan(0, 10, 0) }); // add service limits serviceList[0].Limits.MaxConcurrentPerTemplate = 1; serviceList[0].Limits.MaxConcurrentPerProfile = 1; // create dummy profiles var profileCollection = new ProfilesCollection(); var profile = new ServiceProfile { Name = "profile1" }; profile.Parameters["AccountID"] = 1; profile.Services.Add(profile.DeriveConfiguration(serviceList[0])); profileCollection.Add(profile); profile = new ServiceProfile { Name = "profile2" }; profile.Parameters["AccountID"] = 2; profile.Services.Add(profile.DeriveConfiguration(serviceList[0])); profile.Services[0].SchedulingRules[0].Times[0] = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); profile.Services[0].SchedulingRules[0].MaxDeviationAfter = new TimeSpan(0, 2, 0); profileCollection.Add(profile); profile = new ServiceProfile { Name = "profile3" }; profile.Parameters["AccountID"] = 3; profile.Services.Add(profile.DeriveConfiguration(serviceList[0])); profile.Services[0].SchedulingRules[0].Times[0] = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); profile.Services[0].SchedulingRules[0].MaxDeviationAfter = new TimeSpan(0, 5, 0); profileCollection.Add(profile); schedulerConfig.Profiles = profileCollection; schedulerConfig.ServiceConfigurationList = serviceList; return(schedulerConfig); }
private static void SetupDatabase(ContainerBuilder builder, ILogger <Bootstrapper> logger, SchedulerConfiguration schedulerConfiguration) { logger.LogInformation("Load database"); switch (schedulerConfiguration.StorageProvider) { case StorageProvider.PostgreSql: PostgreSQL.Bootstrapper.SetupDatabaseAndRegisterRepositories(builder, schedulerConfiguration.StorageProviderConnectionString); break; case StorageProvider.RavenDb: RavenDb.Bootstrapper.SetupDatabaseAndRegisterRepositories(builder, schedulerConfiguration.StorageProviderConnectionString); break; default: logger.LogError("The configured value of the setting 'storageProvider' is not supported."); throw new NotSupportedException("The configured value of the setting 'storageProvider' is not supported."); } }
public JobController(ISchedulingService schedulingService, SchedulerConfiguration schedulerConfiguration, IMapper mapper) { _schedulingService = schedulingService; _schedulerConfiguration = schedulerConfiguration; _mapper = mapper; }
public Scheduler(SchedulerConfiguration config) { configuration = config; }
public JobSchedulingController(ISchedulingService schedulingService, SchedulerConfiguration schedulerConfiguration) { _schedulingService = schedulingService; _schedulerConfiguration = schedulerConfiguration; }