public static async Task Run([TimerTrigger("0 */2 * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"Cleanup starting at: {DateTime.Now}");

            Jobs.JobsTable  jobTable    = new Jobs.JobsTable();
            List <Jobs.Job> jobsToClean = (await jobTable.RetrieveAllJobs())
                                          .Where(j => j.status == (int)Jobs.JobStatusCode.Success && j.imageSource != null)
                                          .ToList();

            log.LogInformation($"Found {jobsToClean.Count} successful conversion jobs to clean up");

            CloudStorageAccount storageAccount = Access.GetCloudStorageAccount();
            await Task.WhenAll(
                jobsToClean.Select(j =>
            {
                CloudBlockBlob blob = new CloudBlockBlob(new Uri(j.imageSource), storageAccount.Credentials);
                return(blob.DeleteIfExistsAsync()
                       // Then update table to have no image source
                       .ContinueWith(c => {
                    j.imageSource = null;
                    return jobTable.UpdateJob(j);
                }));
            })
                );
        }
예제 #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/jobs")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Getting status of all jobs");

            try
            {
                Jobs.JobsTable jobTable = new Jobs.JobsTable();
                return(new OkObjectResult(
                           (await jobTable.RetrieveAllJobs())
                           .ConvertAll <DTOJobStatus>(j => new DTOJobStatus(j))
                           .ToList()
                           ));
            }
            catch (Exception ex)
            {
                log.LogError($"Unable to retrieve jobs from job table: {ex.Message}");
                return(new OkObjectResult(new List <DTOJobStatus>()));
            }
        }