public async Task Run([BlobTrigger("databus/{name}", Connection = "DataBusStorageAccount")] CloudBlockBlob myBlob, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { log.LogInformation($"Blob created at {myBlob.Uri}"); var instanceId = myBlob.Name; var existingInstance = await starter.GetStatusAsync(instanceId); if (existingInstance != null) { log.LogInformation($"{nameof(DataBusCleanupOrchestrator)} has already been started for blob {myBlob.Uri}."); return; } var validUntilUtc = calculator.GetValidUntil(myBlob); if (validUntilUtc == DateTime.MaxValue) { log.LogError($"Could not parse the 'ValidUntil' value for blob {myBlob.Uri}. Cleanup will not happen on this blob. You may consider manually removing this entry if non-expiry is incorrect."); return; } await starter.StartNewAsync(nameof(DataBusCleanupOrchestrator), instanceId, new DataBusBlobData { Path = myBlob.Uri.ToString(), ValidUntilUtc = calculator.ToWireFormattedString(validUntilUtc) }); }
public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var counter = 0; try { BlobContinuationToken token = null; do { var segment = await container.ListBlobsSegmentedAsync(token).ConfigureAwait(false); token = segment.ContinuationToken; foreach (var blockBlob in segment.Results.Where(blob => blob is CloudBlockBlob).Cast <CloudBlockBlob>()) { var instanceId = blockBlob.Name; var existingInstance = await starter.GetStatusAsync(instanceId); if (existingInstance != null) { log.LogInformation($"{nameof(DataBusCleanupOrchestrator)} has already been started for blob {blockBlob.Uri}."); continue; } var validUntilUtc = calculator.GetValidUntil(blockBlob); if (validUntilUtc == DateTime.MaxValue) { log.LogError($"Could not parse the 'ValidUntilUtc' value for blob {blockBlob.Uri}. Cleanup will not happen on this blob. You may consider manually removing this entry if non-expiry is incorrect."); continue; } await starter.StartNewAsync(nameof(DataBusCleanupOrchestrator), instanceId, new DataBusBlobData { Path = blockBlob.Uri.ToString(), ValidUntilUtc = calculator.ToWireFormattedString(validUntilUtc) }); counter++; } } while (token != null); } catch (Exception exception) { var result = new ObjectResult(exception.Message) { StatusCode = (int)HttpStatusCode.InternalServerError }; return(result); } var message = "DataBusOrchestrateExistingBlobs has completed." + (counter > 0 ? $" {counter} blob{(counter > 1 ? "s" : string.Empty)} will be tracked for clean-up." : string.Empty); return(new OkObjectResult(message)); }
public static async Task Run( [OrchestrationClient] DurableOrchestrationClient starter, TraceWriter log) { var storageConnectionString = Environment.GetEnvironmentVariable("DataBusStorageAccount"); var cloudStorageAccount = CloudStorageAccount.Parse(storageConnectionString); var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); var container = cloudBlobClient.GetContainerReference("databus"); BlobContinuationToken token = null; do { var segment = await container.ListBlobsSegmentedAsync(token).ConfigureAwait(false); token = segment.ContinuationToken; foreach (var blockBlob in segment.Results.Where(blob => blob is CloudBlockBlob).Cast <CloudBlockBlob>()) { var instanceId = blockBlob.Name; var existingInstance = await starter.GetStatusAsync(instanceId); if (existingInstance != null) { log.Info($"{nameof(DataBusCleanupOrchestrator)} has already been started for blob {blockBlob.Uri}."); continue; } var validUntilUtc = DataBusBlobTimeoutCalculator.GetValidUntil(blockBlob); if (validUntilUtc == DateTime.MaxValue) { log.Error($"Could not parse the 'ValidUntil' value `{blockBlob.Metadata["ValidUntil"]}` for blob {blockBlob.Uri}. Cleanup will not happen on this blob. You may consider manually removing this entry if non-expiry is incorrect."); continue; } await starter.StartNewAsync(nameof(DataBusCleanupOrchestrator), instanceId, new DataBusBlobData { Path = blockBlob.Uri.ToString(), ValidUntilUtc = DataBusBlobTimeoutCalculator.ToWireFormattedString(validUntilUtc) }); } } while (token != null); }