public static void Run( [QueueTrigger(JobTracker.ZipBuilderQueue, Connection = "ConnectionStrings:Storage")] string data, ILogger log, ExecutionContext context) { int id = int.Parse(data); // int because JobTracker is QueuedJob<int> var config = context.GetConfig(); var databaseConnection = config["ConnectionStrings:Database"]; var storageConnection = config["ConnectionStrings:Storage"]; var statusUpdateUrl = config["StatusUpdateUrl"]; var repo = new JobTrackerRepository(databaseConnection); new ZipFileBuilder(storageConnection, (id) => $"{statusUpdateUrl}/{id}", repo, log) .ExecuteAsync(id) .Wait(); }
private void ZipBuilderInner(bool postUpdates) { // since this is testing a real job, I need to pass real connection strings from that project var dbConnection = Config["Values:ConnectionStrings:Database"]; var repo = new JobTrackerRepository(dbConnection); var logger = LoggerFactory.Create(config => config.AddDebug()).CreateLogger("testing"); // I already have some blobs in this location in this account. // a more robust test would upload some files first rather than assume these var job = QueueClientExtensions.SaveJobAsync(repo, "adamo", new ZipRequest() { ContainerName = "sample-uploads", BlobPrefix = "anonUser" }).Result; var storageConnection = Config["Values:ConnectionStrings:Storage"]; var function = new ZipFileBuilder(storageConnection, (id) => $"https://localhost:44377/JobUpdated/{id}", repo, logger) { PostStatusUpdates = postUpdates }; var result = function.ExecuteAsync(job.Id).Result; // verify the download works var response = _client.GetAsync(result.Url).Result; response.EnsureSuccessStatusCode(); // and is a valid zip file var tempFile = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".zip"); using (var downloadFile = File.Create(tempFile)) { response.Content.CopyToAsync(downloadFile).Wait(); } using (var zipFile = ZipFile.OpenRead(tempFile)) { Assert.IsTrue(zipFile.Entries.Any()); } File.Delete(tempFile); }
public ZipFileBuilder(string storageConnection, Func <int, string> endpointBuilder, JobTrackerRepository repository, ILogger logger) : base(repository, logger) { _storageConnection = storageConnection; _endpointBuilder = endpointBuilder; }