Skip to content

Instantly share code, notes, and snippets.

@spboyer
Created August 11, 2018 15:45
Show Gist options
  • Save spboyer/586ff7630593347a82625d383ce86a5c to your computer and use it in GitHub Desktop.
Save spboyer/586ff7630593347a82625d383ce86a5c to your computer and use it in GitHub Desktop.
serverless-cdn script
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