示例#1
0
        public void ChangePeriod_TimerStartedPeriodChangedAfterFirstCall_PeriodChangedBeforeNextCall()
        {
            var entity = new Entity {
                Id = "entity0"
            };
            Entity lastInvokedEntity = null;
            var    timerFactory      = new TestTimerFactory();

            using var scheduler = new EntityActionScheduler <Entity>(e =>
            {
                lastInvokedEntity = e;
                return(Task.CompletedTask);
            }, autoStart: true, runOnce: false, timerFactory);

            scheduler.ScheduleEntity(entity, TimeSpan.FromMilliseconds(Period0));
            timerFactory.VerifyTimer(0, Period0);

            timerFactory.FireTimer(0);

            var newPeriod = TimeSpan.FromMilliseconds(Period1);

            scheduler.ChangePeriod(entity, newPeriod);

            timerFactory.VerifyTimer(0, Period1);
            Assert.Same(entity, lastInvokedEntity);
        }
示例#2
0
        public void OnClusterChanged(ClusterInfo cluster)
        {
            var activeHealthCheckOptions = cluster.Config.HealthCheckOptions.Active;

            if (activeHealthCheckOptions.Enabled)
            {
                _scheduler.ChangePeriod(cluster, activeHealthCheckOptions.Interval ?? _monitorOptions.DefaultInterval);
            }
            else
            {
                _scheduler.UnscheduleEntity(cluster);
            }
        }