Last active
August 29, 2016 19:33
-
-
Save ahelland/698c6acfd44a0590f5f708f758a841c9 to your computer and use it in GitHub Desktop.
Azure Function running on a self-modifying random schedule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
public static void Run(TimerInfo myTimer, TraceWriter log) | |
{ | |
log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); | |
//Read current settings | |
string[] settings = File.ReadAllLines(@"D:\home\site\wwwroot\RandomTrigger\function.json"); | |
var schedule = settings[6]; | |
log.Info($"Current schedule: {schedule}"); | |
Random rnd = new Random(); | |
//Random number from 0 to 59 | |
var randomInterval = rnd.Next(60); | |
//Create a new schedule | |
schedule = $"\t\t\"schedule\": \"{randomInterval} * * * * *\""; | |
//Overwrite original settings file | |
settings[6] = schedule; | |
File.WriteAllLines(@"D:\home\site\wwwroot\RandomTrigger\function.json", settings); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment