static void RunAutoscaler() { ILoadWatcher loadWatcher = new DocumentDBWatcher(_endpoint, _authKey, _database); var pools = loadWatcher.GetPools(); if (pools != null) { ScaleSetScaler autoScaler = new ScaleSetScaler( pools.ClientId, pools.ClientSecret, pools.TenantId, pools.SubscriptionId); foreach (var pool in pools.RgVmssName) { var words = pool.Split(','); autoScaler.AddScaleset(words[0], words[1]); } autoScaler.SetLoadWatcher(loadWatcher); autoScaler.TraceEvent += AutoScaler_TraceEvent; while (!Console.KeyAvailable) { Task t = autoScaler.AutoScale(); t.Wait(); double minutes = 5; Trace.WriteLine($"Pausing for {minutes} minutes"); Task.Delay((int)(60 * 1000 * minutes)).Wait(); } } }
public static void Run(TimerInfo myTimer, TraceWriter log) { Log = log; log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); ILoadWatcher loadWatcher = new DocumentDBWatcher(ConfigurationManager.AppSettings["endpoint"], ConfigurationManager.AppSettings["authKey"], ConfigurationManager.AppSettings["database"]); var pools = loadWatcher.GetPools(); if (pools != null) { ScaleSetScaler autoScaler = new ScaleSetScaler( pools.ClientId, pools.ClientSecret, pools.TenantId, pools.SubscriptionId); foreach (var pool in pools.RgVmssName) { log.Info($"Adding {pool}"); var words = pool.Split(','); autoScaler.AddScaleset(words[0], words[1]); } autoScaler.SetLoadWatcher(loadWatcher); autoScaler.TraceEvent += AutoScaler_TraceEvent; autoScaler.AutoScale().Wait(); } else { log.Info($"No pool configured"); } }