Created
August 11, 2018 15:45
-
-
Save spboyer/586ff7630593347a82625d383ce86a5c to your computer and use it in GitHub Desktop.
serverless-cdn script
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.IO; | |
using System.Net.Http; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Host; | |
using Microsoft.WindowsAzure.Storage.Blob; | |
namespace Workshop.Function | |
{ | |
public static class cdn_cache_thing | |
{ | |
private static HttpClient client = new HttpClient { BaseAddress = new Uri("https://aspnetcorews-backend.azurewebsites.net") }; | |
[FunctionName("cdn-cache-thing")] | |
public static async Task Run( | |
[TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, | |
[Blob("images/sessions.json", FileAccess.Write)] CloudBlockBlob sessionFile, | |
TraceWriter log) | |
{ | |
using (var response = await client.GetAsync("/api/Sessions")) | |
{ | |
var responseStream = await response.Content.ReadAsStreamAsync(); | |
sessionFile.Properties.ContentType = "application/json"; | |
await sessionFile.UploadFromStreamAsync(responseStream); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment