/// <summary> /// Set the timezone that the schedule should work in from the region of the resource /// or the tag (if one has been set) /// </summary> public void SetTimeZone() { // get the id of the zone string zoneId = String.Empty; // determine if the resource has a timezone tag set on it string tagZone = GetTag("tag_timezone"); // if the tagZone is not empty, get the zone from that // otherwise use the resource region to get the zone if (!string.IsNullOrEmpty(tagZone)) { zoneId = tagZone; } else { // Find the TimeZoneInfo based on the regionName LocationTZ resourceZone = _timeZones.First(t => t.name == _regionName); zoneId = resourceZone.tzId; } // zoneInfo = TimeZoneInfo.FindSystemTimeZoneById(zoneId); zoneInfo = TimeZoneConverter.TZConvert.GetTimeZoneInfo(zoneId); // work out the offset to be used for calculating times, based on the // specified timezone of the resource _timzoneNow = TimeZoneInfo.ConvertTimeFromUtc(_timeNowUTC, zoneInfo); }
/// <summary> /// Set the timezone that is to be used for time comparison /// The precendence of this is: /// 1. Tags /// 2. Location of virtual machine /// 3. Utc /// </summary> private void SetTimeZone() { // Find the TimeZoneInfo based on the location of the VM LocationTZ vmZone = timezones.First(t => t.name == virtualMachine.RegionName); if (vmZone != null) { zoneInfo = TimeZoneInfo.FindSystemTimeZoneById(vmZone.tzId); } // Set the zone if the vm has a tag that states what zone it is in dynamic tagZone = HasTag("tag_timezone"); if (tagZone) { zoneInfo = TimeZoneInfo.FindSystemTimeZoneById((string)tagZone); } }
/// <summary> /// runReaper executes the Reaper for the timer process /// It is responsible for gathering the settings and the current subscription /// that are required by the reaper. This is so that the reaper does not need to /// access the DB directly /// </summary> private async Task runReaper() { Response response = new Response(); List <Models.Setting> settings = new List <Models.Setting>(); List <Models.Subscription> subscriptions = new List <Models.Subscription>(); List <Models.LocationTZ> locationTZs = new List <Models.LocationTZ>(); // get the necessary settings by category string[] categories = new string[] { "tags", "slack", "lifecycle" }; // get the settings the reaper will use Dictionary <string, dynamic> criteria = new Dictionary <string, dynamic>(); criteria.Add("category", categories); IModel setting = new Setting(_backend, _logger); response = setting.Get(criteria); settings = response.GetData(); // get the subscriptions known to the system IModel subscription = new Subscription(_backend, _logger); response = subscription.GetByName(); subscriptions = response.GetData(); // get the location timezones known to the system LocationTZ locationTZ = new LocationTZ(_backend, _logger); // Create a notification delay object for the reaper to work with NotificationDelay notificationDelay = new NotificationDelay(_backend, _logger); // Create an instance of the reaper and process it Reaper reaper = new Reaper(_backend, _logger, settings, notificationDelay); reaper.Process(subscriptions, locationTZ); }
// Global initialisation public TestsFixture() { // Create a new logger for the tests logger = new Azure.Reaper.Lib.Loggers.AppSerilog(); // configure settings for the tests // these are to emulate the data that is retrieved from the database when running as a function settings = new List <Setting>(); // add in the necessary settings for the tests // -- start stop tag Setting setting1 = new Setting(); setting1.name = "tag_vm_start_stop_time"; setting1.value = "STARTSTOPTIME"; settings.Add(setting1); // -- name of the tag for setting the timezone Setting setting2 = new Setting(); setting2.name = "tag_timezone"; setting2.value = "TIMEZONE"; settings.Add(setting2); // -- set the days that resources are permitted to run on Setting setting3 = new Setting(); setting3.name = "permitted_days"; setting3.value = "1,2,3,4,5"; settings.Add(setting3); // -- add the tag that holds the days of the week the resource is // allowed to run on Setting setting4 = new Setting(); setting4.name = "tag_days_of_week"; setting4.value = "DAYSOFWEEK"; settings.Add(setting4); // -- add the settings for the start and stop times of resources Setting setting5 = new Setting(); setting5.name = "vm_start"; setting5.value = "0800"; settings.Add(setting5); Setting setting6 = new Setting(); setting6.name = "vm_stop"; setting6.value = "1800"; settings.Add(setting6); Setting setting7 = new Setting(); setting7.name = "tag_inuse"; setting7.value = "InUse"; settings.Add(setting7); // configure necessary timezones timeZones = new List <LocationTZ>(); LocationTZ tz1 = new LocationTZ(); tz1.name = "ukwest"; tz1.tzId = "GMT Standard Time"; timeZones.Add(tz1); LocationTZ tz2 = new LocationTZ(); tz2.name = "westcentralus"; tz2.tzId = "Mountain Standard Time"; timeZones.Add(tz2); }