Created
August 24, 2020 12:49
-
-
Save LauraKokkarinen/d048e94239a54bf3b02eb4559ee86464 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 System.Threading.Tasks; | |
using AzureFunctionsDependencyInjection.Services; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Extensions.Logging; | |
namespace AzureFunctionsDependencyInjection | |
{ | |
public class CacheRefresh | |
{ | |
private readonly IDataService _dataService; | |
public CacheRefresh(IDataService dataService) | |
{ | |
_dataService = dataService; | |
} | |
//Refreshes the cache once per hour | |
[FunctionName("CacheRefresh")] | |
public async Task RunAsync([TimerTrigger("0 0 * * * *")] TimerInfo myTimer, ILogger log) | |
{ | |
try | |
{ | |
await _dataService.GetAndCacheDataAsync(); | |
log.LogInformation($"Successfully refreshed cache."); | |
} | |
catch (Exception e) | |
{ | |
log.LogError($"Failed to refresh cache: {e.Message}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment