Пример #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                foreach (var crawler in runningCrawlers)
                {
                    var process = Process.GetProcesses().FirstOrDefault(process => process.Id == crawler.ProcessId);
                    if (process == null)
                    {
                        //Set on queues return of sheets
                        if (crawler.Images.Count == 0)
                        {
                            _mq.WriteMessage(ControllerConstants.NoDataMessage, crawler.QueueReturnName);
                        }
                        else
                        {
                            foreach (var image in crawler.Images)
                            {
                                _mq.WriteMessage(image, crawler.QueueReturnName);
                            }
                        }

                        crawler.ToErase = true;
                    }
                }

                RemoveAlreadyQueriedCrawlers();

                await Task.Delay(2000, stoppingToken);
            }
        }
Пример #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            //Get sheet name and get where should search it
            string name      = req.Query["name"];
            string queueName = req.Query["queue"];

            if (string.IsNullOrEmpty(name))
            {
                using (var stream = new StreamReader(req.Body))
                {
                    string requestBody = await stream.ReadToEndAsync();

                    dynamic data = JsonConvert.DeserializeObject(requestBody);
                    name      = data?.name;
                    queueName = data?.queue;
                }
            }

            //Create MQ message
            var desiredQueue = _database.GetBestQueue();

            log.LogInformation($"Sending information to queue '{desiredQueue}'...");
            _mqConnection.CreateQueue(desiredQueue);
            _mqConnection.WriteMessage($"--termo {name} --tipo 0|{queueName}", desiredQueue);
            log.LogInformation($"Sent!");

            return(new OkObjectResult("MQ sent"));
        }