Esempio n. 1
0
        public async Task <bool> HandleRecievedItemAsync <TCommand, TResult>(QueueItem <TCommand> item, int maxDequeueCount) where TCommand : class, ICommand <TResult>
        {
            try
            {
                _logger.LogInfo($"Recieved command {item.GetType().Name} from queue");
                bool shouldDequeue = true;
                IQueueableCommand queueableCommand = item.Item as IQueueableCommand;
                if (queueableCommand != null)
                {
                    queueableCommand.DequeueCount = item.DequeueCount;
                }
                Task commandTask = _commandExecuter.ExecuteAsync(item.Item);
                while (!commandTask.Wait(TimeSpan.FromSeconds(10)))
                {
                    await item.ExtendLeaseAsync();
                }

                if (queueableCommand != null)
                {
                    shouldDequeue = queueableCommand.ShouldDequeue;
                }
                _logger.LogInfo($"Completed processing command {item.GetType().Name} and returning a shouldDequeue status of {shouldDequeue}");
                return(shouldDequeue);
            }
            catch (Exception ex)
            {
                if (item.DequeueCount > maxDequeueCount)
                {
                    _logger.LogError($"Error during processing command of type {item.GetType().Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {item.DequeueCount}, will not try again.", item.Item, ex);
                    return(true);
                }
                _logger.LogWarning($"Error during processing command of type {item.GetType().Name} with exception of type {ex.GetType().AssemblyQualifiedName}. Dequeue count is {item.DequeueCount}, will try again.", item.Item, ex);
                return(false);
            }
        }
Esempio n. 2
0
        public async Task InvokeAsync()
        {
            var instanceWorkerId = _workerRecordStoreService.GenerateUniqueId();

            Console.WriteLine($"CommandExecuter {instanceWorkerId} starting...");
            await _workerRecordStoreService.RecordPing("commandExecuter", instanceWorkerId);

            var commandQueueMessages = await _queueClient.Dequeue(_config.CommandQueueName, _config.MaxQueueItemsBatchSizeToProcessPerWorker);

            if (commandQueueMessages.Count == 0)
            {
                await _workerRecordStoreService.RecordHasTerminated("commandExecuter", instanceWorkerId);

                return;
            }

            foreach (var commandQueueMessage in commandQueueMessages)
            {
                var serializerSettings = new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                };
                var command = JsonConvert.DeserializeObject <NoResultCommandWrapper>(commandQueueMessage.Message, serializerSettings);
                await _directCommandExecuter.ExecuteAsync(command);

                await _queueClient.MessageProcessed(_config.CommandQueueName, commandQueueMessage.MessageId);
            }

            await _workerRecordStoreService.RecordHasTerminated("commandExecuter", instanceWorkerId);

            Console.WriteLine($"Mapper {instanceWorkerId} Terminated");
        }
Esempio n. 3
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger logger)
        {
            Logger.Value = logger;
            logger.LogInformation("C# HTTP trigger function processed a request.");

            IDirectCommandExecuter executer = ServiceProvider.GetService <IDirectCommandExecuter>();

            GetStoreProductQuery query = new GetStoreProductQuery
            {
                ProductId = Guid.Parse(req.GetQueryParameterDictionary()["ProductId"])
            };
            CommandResponse <StoreProduct> result = await executer.ExecuteAsync(query);

            return(new OkObjectResult(result));
        }
Esempio n. 4
0
        public async Task <UpdateResult> Put([FromBody] UpdatePersonalDetailsCommand command)
        {
            UpdateResult result = await _commandExecuter.ExecuteAsync(command);

            return(result);
        }