Пример #1
0
        private void CheckWorkersAvailability(object sender, ElapsedEventArgs eventArgs)
        {
            var workers = ImageWorkerRepository.Instance.FindAll().ToList();

            if (workers == null || !workers.Any())
            {
                return;
            }

            foreach (var imageWorker in workers)
            {
                try
                {
                    var restImageProcessorClient = new RestImageProcessorClient(imageWorker.WorkerServiceUrl);
                    restImageProcessorClient.SetKeplerServiceUrl();

                    imageWorker.WorkerStatus = ImageWorker.StatusOfWorker.Available;
                }
                catch (Exception ex)
                {
                    ErrorMessageRepository.Instance.Insert(new ErrorMessage()
                    {
                        ExceptionMessage = $"Image worker: '{imageWorker.Name}' is unavailable. {ex.Message}"
                    });
                    imageWorker.WorkerStatus = ImageWorker.StatusOfWorker.Offline;
                }
                finally
                {
                    ImageWorkerRepository.Instance.Update(imageWorker);
                }
            }
        }
Пример #2
0
        public void UpdateKeplerServiceUrlOnWorkers()
        {
            var workers = ImageWorkerRepository.Instance.FindAll()
                          .Where(worker => worker.WorkerStatus == ImageWorker.StatusOfWorker.Available).ToList();

            foreach (var imageWorker in workers)
            {
                var restImageProcessorClient = new RestImageProcessorClient(imageWorker.WorkerServiceUrl);
                restImageProcessorClient.SetKeplerServiceUrl();
            }
        }
Пример #3
0
        public void RegisterImageWorker(string name, string imageWorkerServiceUrl)
        {
            imageWorkerServiceUrl = imageWorkerServiceUrl.Trim();

            var workerRepo = ImageWorkerRepository.Instance;

            if (!workerRepo.Find(new { Name = imageWorkerServiceUrl }).Any())
            {
                workerRepo.Insert(new ImageWorker
                {
                    Name             = name,
                    WorkerServiceUrl = imageWorkerServiceUrl
                });

                var restImageWorkerClient = new RestImageProcessorClient(imageWorkerServiceUrl);
                restImageWorkerClient.SetKeplerServiceUrl();
            }
            else
            {
                LogErrorMessage(ErrorMessage.ErorCode.NotUniqueObjects,
                                $"Image worker with the same URL {imageWorkerServiceUrl} already exist");
            }
        }