public StatelessServiceScaler(CancellationToken cancellationToken, ScalingRule rule, params string[] servicesNames)
        {
            this.rule = rule;
            this.serviceNameToScale = servicesNames;

            this.lastScaleDate = DateTime.MinValue;
            cancelSource       = new CancellationTokenSource();
        }
예제 #2
0
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            var rule = new ScalingRule()
            {
                MinimalInstanceCount = 1,  // always maintain 1 instance up
                MaximalInstanceCount = 5,  // maximum is 5 instance count
                DecreaseThreshold    = 1,  // decrease instance count if less than 1 message in queue
                IncreaseThreshold    = 10, // increase +1 instance count if higher than 10 message in queue
                DelayBetweenScaling  = 10
            };

            // TODO : replace the services names to scale by dynamic name constructing/retrieving.
            scaler = new StatelessServiceScaler(cancellationToken, rule, "fabric://Hackfest/generator");

            await base.RunAsync(cancellationToken);
        }