public IActionResult Get(string id)
        {
            var process = processQuery.Get(id);

            if (process == null)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status404NotFound,
                                                         string.Format(ProcessResources.ProcessWithId_0_DoesNotFound, id)));
            }

            return(new OkObjectResult(process.ToProcessModel()));
        }
예제 #2
0
        public void MaintainBusyServices()
        {
            var busyServices = serviceQuery.GetAll().Where(s => s.Status == (int)ServiceStatusEnum.Busy).ToList();

            var classifierHandler = serviceProvider.GetService <ClassifierServiceHandler>();
            var prcHandler        = serviceProvider.GetService <PrcServiceHandler>();

            foreach (var service in busyServices)
            {
                var lastProcess = processQuery.Get(service.ProcessIdList.Last());

                //if the last process was a preparation then the service will be in New status
                if (lastProcess.Type == (int)ProcessTypeEnum.ClassifierPrepare ||
                    lastProcess.Type == (int)ProcessTypeEnum.PrcPrepare)
                {
                    service.Status = (int)ServiceStatusEnum.New;
                }

                //if the last process was an activation then the service will be in Activated status (so the API can Activate the service)
                else if (lastProcess.Type == (int)ProcessTypeEnum.ClassifierActivate ||
                         lastProcess.Type == (int)ProcessTypeEnum.PrcActivate)
                {
                    service.Status = (int)ServiceStatusEnum.Active;
                }

                //otherwise it will be New
                else
                {
                    service.Status = (int)ServiceStatusEnum.New;
                }

                serviceQuery.Update(service.Id, service);

                //if a preparation failed, then we need to delete the dictionaries directory (maybe in the future we can continue it...)
                if (service.Status == (int)ServiceStatusEnum.New)
                {
                    var dirPath = "";
                    if (service.Type == (int)ServiceTypeEnum.Classifier)
                    {
                        dirPath = classifierHandler.GetDirectoryPath(service.Id);
                    }
                    if (service.Type == (int)ServiceTypeEnum.Prc)
                    {
                        dirPath = prcHandler.GetDirectoryPath(service.Id);
                    }
                    IOHelper.SafeDeleteDictionary(dirPath, true);
                }
            }
        }
예제 #3
0
        public void Interrupted(string processId, Exception ex)
        {
            Serilog.Log.Error(ex, ProcessResources.FatalErrorOccuredDuringTheOperation + " {ProcessID}", processId);

            var process = GlobalStore.Processes.IsExist(processId) ? GlobalStore.Processes.Get(processId).Process : processQuery.Get(processId);

            process.End = DateTime.UtcNow;

            process.ErrorMessages.Add(ProcessResources.FatalErrorOccuredDuringTheOperation);
            if (ex is Common.Exceptions.SlambyException)
            {
                process.ErrorMessages.Add(ex.Message);
            }
            process.Status = (int)ProcessStatusEnum.Error;

            if (GlobalStore.Processes.IsExist(processId))
            {
                GlobalStore.Processes.Remove(processId);
            }
            processQuery.Update(processId, process);
        }