示例#1
0
        public IActionResult GetPredictionStatus(Guid id)
        {
            var prediction = _keyValueRepository.LoadObject <dynamic>(id);

            if (prediction == null)
            {
                return(NotFound());
            }

            return(Ok(new { Id = id, Status = prediction["status"] }));
        }
示例#2
0
        public HttpResponseMessage Get(string id)
        {
            Log.Information($"Getting file {id}");
            var descriptor = _repository.LoadObject <FileDescriptor>(id);

            if (descriptor == null)
            {
                Log.Information($"File's {id} descriptor not found.");
                return(Request.CreateResponse(HttpStatusCode.NotFound, "File with same id not found"));
            }

            if (!string.IsNullOrEmpty(descriptor.ProcessingInfoId))
            {
                var processingInfo = _repository.LoadObject <ProcessingInfo>(descriptor.ProcessingInfoId);
                if (processingInfo != null)
                {
                    if (string.IsNullOrEmpty(processingInfo.ProcessingError))
                    {
                        Log.Information($"File {id} is being processed.");
                        return(Request.CreateResponse(HttpStatusCode.Accepted, $"Image {id} is being processed"));
                    }
                    else
                    {
                        // The file processing resulted in an error
                        Log.Information($"File {id} processed with error: {processingInfo.ProcessingError}.");
                        return(Request.CreateResponse(
                                   HttpStatusCode.NoContent, $"Image {id} is not available. {processingInfo.ProcessingError}"));
                    }
                }
                else
                {
                    // We have processing info ID but couldn't find the ProcessingInfo object
                    return(Request.CreateResponse(
                               HttpStatusCode.Conflict, $"Processing data incosistency. Please delete file {id} and retry."));
                }
            }

            if (string.IsNullOrEmpty(descriptor.BlobId))
            {
                // We have failed to produce a blob even though there is no processing error
                Log.Information($"File {id} is being processed.");
                return(Request.CreateResponse(
                           HttpStatusCode.Conflict, $"Processing data incosistency. Please delete file {id} and retry."));
            }

            // The file processing was successfuly and we have the blob
            Log.Information($"File {id} found. Sending...");
            return(HttpResponseWithStream(descriptor.DescriptorId, descriptor.BlobId, descriptor.FileName));
        }
示例#3
0
        public Task Consume(ConsumeContext <PredictedResultReady> context)
        {
            var prediction      = _keyValueRepository.LoadObject <dynamic>(context.Message.Id);
            var softwareInfo    = $@"{{
                              'software': '{_sspSettings.Software}',
                              'version': '{Assembly.GetEntryAssembly().GetVersion()}'
                        }}";
            var softwareInfoObj = JsonConvert.DeserializeObject <dynamic>(softwareInfo);
            var response        = context.Message.Data;

            response.provider   = softwareInfoObj;
            prediction.response = response;

            prediction.status = "COMPLETE";
            _keyValueRepository.SaveObject(context.Message.Id, prediction);
            _keyValueRepository.SetExpiration(context.Message.Id, TimeSpan.Parse(_sspSettings.RedisExpirationTime));
            return(Task.CompletedTask);
        }