Exemplo n.º 1
0
        private async Task SetDelayTimeAndSendDelayedRetry(
            IConfiguration configuration,
            ServiceBusSendQueueMessageContent queueMessageContent)
        {
            // Simply initialize the variable for certain build environments and versions
            var sendRetryDelayNumberOfMinutes = 0;

            // If parsing fails, out variable is set to 0, so need to set the default
            if (!int.TryParse(configuration["SendRetryDelayNumberOfMinutes"], out sendRetryDelayNumberOfMinutes))
            {
                sendRetryDelayNumberOfMinutes = 11;
            }

            // Shorten this time by 15 seconds to ensure that when the delayed retry message is taken off of the queue
            // the Send Retry Delay Time will be earlier and will not block it
            var sendRetryDelayTime = DateTime.UtcNow + TimeSpan.FromMinutes(sendRetryDelayNumberOfMinutes - 0.25);

            var globalSendingNotificationDataEntity = new GlobalSendingNotificationDataEntity
            {
                SendRetryDelayTime = sendRetryDelayTime,
            };

            await CompanyCommunicatorSendFunction.globalSendingNotificationDataRepository
            .SetGlobalSendingNotificationDataEntity(globalSendingNotificationDataEntity);

            await this.SendDelayedRetryOfMessageToSendFunction(configuration, queueMessageContent);
        }
        /// <summary>
        /// This method sets the globally accessible delay time indicating to all other functions that the system is currently in a
        /// throttled state and all messages need to be delayed and sends the queue message back to the queue with a delayed wait time.
        /// </summary>
        /// <param name="sendRetryDelayNumberOfSeconds">The number of seconds for the system and message to be delayed.</param>
        /// <param name="sendQueueMessageContent">The send queue message content to be sent back to the send queue for a delayed retry.</param>
        /// <param name="log">The logger.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task DelaySendingNotificationAsync(
            double sendRetryDelayNumberOfSeconds,
            SendQueueMessageContent sendQueueMessageContent,
            ILogger log)
        {
            try
            {
                // Shorten this time by 15 seconds to ensure that when the delayed retry message is taken off of the queue
                // the Send Retry Delay Time will be earlier and will not block it
                var sendRetryDelayTime = DateTime.UtcNow + TimeSpan.FromSeconds(sendRetryDelayNumberOfSeconds - 15);

                var globalSendingNotificationDataEntity = new GlobalSendingNotificationDataEntity
                {
                    SendRetryDelayTime = sendRetryDelayTime,
                };

                var setGlobalSendingNotificationDataEntityTask = this.globalSendingNotificationDataRepository
                                                                 .SetGlobalSendingNotificationDataEntityAsync(globalSendingNotificationDataEntity);

                var sendDelayedRetryTask = this.sendQueue.SendDelayedAsync(sendQueueMessageContent, sendRetryDelayNumberOfSeconds);

                await Task.WhenAll(
                    setGlobalSendingNotificationDataEntityTask,
                    sendDelayedRetryTask);
            }
            catch (Exception e)
            {
                log.LogError(e, $"ERROR: {e.GetType()}: {e.Message}");
                throw;
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public async Task SetSendNotificationThrottled(double sendRetryDelayNumberOfSeconds)
        {
            // Ensure global retry timestamp is less re-queue delay time for the message.
            var globalSendingNotificationDataEntity = new GlobalSendingNotificationDataEntity
            {
                SendRetryDelayTime = DateTime.UtcNow + TimeSpan.FromSeconds(sendRetryDelayNumberOfSeconds - 15),
            };

            await this.globalSendingNotificationDataRepository
            .SetGlobalSendingNotificationDataEntityAsync(globalSendingNotificationDataEntity);
        }
Exemplo n.º 4
0
        public async Task SendNotificationThrottled_SendRetrydelayTime_Test()
        {
            // Arrange
            var notificationService = GetNotificationService();
            GlobalSendingNotificationDataEntity globalSendingNofificationDataResponse = new GlobalSendingNotificationDataEntity();

            globalSendingNotificationDataRepository
            .Setup(x => x.GetGlobalSendingNotificationDataEntityAsync())
            .ReturnsAsync(globalSendingNofificationDataResponse);

            // Act
            var serviceResponse = await notificationService.IsSendNotificationThrottled();

            // Assert
            serviceResponse.Should().BeFalse();
        }
Exemplo n.º 5
0
        public async Task SendNotificationThrottledTest()
        {
            // Arrange
            var notificationService = GetNotificationService();
            var globalSendingNofificationDataResponse = new GlobalSendingNotificationDataEntity()
            {
                SendRetryDelayTime = DateTime.UtcNow - TimeSpan.FromSeconds(1),
            };

            globalSendingNotificationDataRepository
            .Setup(x => x.GetGlobalSendingNotificationDataEntityAsync())
            .ReturnsAsync(globalSendingNofificationDataResponse);

            // Act
            var serviceResponse = await notificationService.IsSendNotificationThrottled();

            // Assert
            serviceResponse.Should().BeFalse();
        }