Created
August 24, 2020 12:49
-
-
Save LauraKokkarinen/cb56d23bacbde2d4465432c1154fed0f to your computer and use it in GitHub Desktop.
This file contains 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 Microsoft.Azure.WebJobs; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Logging; | |
namespace AzureFunctionsDependencyInjection | |
{ | |
public class Warmup | |
{ | |
private readonly IConfiguration _configuration; | |
public Warmup(IConfiguration configuration) | |
{ | |
_configuration = configuration; | |
} | |
// The function app goes to sleep after 20 minutes of inactivity, trigger with a shorter interval to keep it awake. | |
[FunctionName("Warmup")] | |
public void Run([TimerTrigger("0 */15 * * * *")] TimerInfo myTimer, ILogger log) | |
{ | |
var urls = _configuration["FunctionUrls"].Split(';'); | |
foreach (string url in urls) | |
{ | |
try | |
{ | |
// TODO: Handle auth and make a GET request to each of the function URLs with a query string param ?warmup=true | |
log.LogInformation($"Successfully warmed up a function at {url}"); | |
} | |
catch (Exception e) | |
{ | |
log.LogError($"Failed to warmup a function at {url}. {e.Message}"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment