Skip to content

Instantly share code, notes, and snippets.

@ahelland
Last active August 29, 2016 19:33
Show Gist options
  • Save ahelland/698c6acfd44a0590f5f708f758a841c9 to your computer and use it in GitHub Desktop.
Save ahelland/698c6acfd44a0590f5f708f758a841c9 to your computer and use it in GitHub Desktop.
Azure Function running on a self-modifying random schedule
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