/// <summary> /// Returns a JobEntityResponse DTO for /// every job entity in the jobs table. /// /// This is intended to be used by the /// job status API /// </summary> /// <returns></returns> public List <JobEntityResponse> RetrieveAllJobEntities() { TableQuery <JobEntity> tableQuery = new TableQuery <JobEntity>(); TableContinuationToken token = null; List <JobEntity> jobEntityList = new List <JobEntity>(); List <JobEntityResponse> jobEntityResponseList = new List <JobEntityResponse>(); // Continue to make requests until no continuation token is found // The table API will respond with up to 1000 results do { var result = _table.ExecuteQuerySegmentedAsync(tableQuery, token).GetAwaiter().GetResult(); jobEntityList.AddRange(result.Results); token = result.ContinuationToken; }while (token != null); foreach (JobEntity jobEntity in jobEntityList) { JobEntityResponse jobEntityResponse = new JobEntityResponse() { JobId = jobEntity.RowKey, ImageConversionMode = jobEntity.ImageConversionMode, Status = jobEntity.Status, StatusDescription = jobEntity.StatusDescription, ImageSource = jobEntity.ImageSource, ImageResult = jobEntity.ImageResult, }; jobEntityResponseList.Add(jobEntityResponse); } return(jobEntityResponseList); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "jobs/{id}")] HttpRequest req, string id, ILogger log) { if (string.IsNullOrEmpty(id)) { return(new BadRequestObjectResult("The query string id is required")); } if (id.Length > 36) { return(new BadRequestObjectResult("An id cannot be greater than 36 characters")); } log.LogInformation("[PENDING] Connecting to jobs table..."); JobTable jobTable = new JobTable(log, ConfigSettings.IMAGEJOBS_PARTITIONKEY); log.LogInformation("[SUCCESS] Connected to Jobs Table"); log.LogInformation("[PENDING] Searching for Job Entity {id}..."); JobEntity jobEntity = await jobTable.RetrieveJobEntity(id); if (jobEntity == null) { log.LogError("Job Entity {id} was not found"); ErrorResponse errorResponse = ErrorResponse.New(ErrorResponseCodes.NOT_FOUND, "JobId", id, ErrorResponseMessages.NOT_FOUND); return(new NotFoundObjectResult(errorResponse)); } log.LogInformation("[SUCCESS] Job Entity {id} was found"); JobEntityResponse jobEntityResponse = JobEntityResponse.New( jobEntity.RowKey, jobEntity.ImageConversionMode, jobEntity.Status, jobEntity.StatusDescription, jobEntity.ImageSource, jobEntity.ImageResult); return(new OkObjectResult(jobEntityResponse)); }