public async void Run([TimerTrigger("0 0 * * * *")] TimerInfo myTimer, ILogger log) { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); var strFilter = "PublishOn eq '" + this.RoundAndFormatDateTime() + "'"; var draftNotifications = await this.notificationDataRepository.GetWithFilterAsync(strFilter); foreach (var draftEntity in draftNotifications) { var newSentNotificationId = await this.notificationDataRepository.MoveDraftToSentPartitionAsync(draftEntity); var prepareToSendQueueMessageContent = new PrepareToSendQueueMessageContent { NotificationId = newSentNotificationId, }; await this.prepareToSendQueue.SendAsync(prepareToSendQueueMessageContent); var forceCompleteDataQueueMessageContent = new DataQueueMessageContent { NotificationId = newSentNotificationId, ForceMessageComplete = true, }; await this.dataQueue.SendDelayedAsync( forceCompleteDataQueueMessageContent, this.forceCompleteMessageDelayInSeconds); } }
public async Task Run( [ServiceBusTrigger( DataQueue.QueueName, Connection = DataQueue.ServiceBusConnectionConfigurationKey)] string myQueueItem, int deliveryCount, DateTime enqueuedTimeUtc, string messageId, ILogger log, ExecutionContext context) { var messageContent = JsonConvert.DeserializeObject <DataQueueMessageContent>(myQueueItem); var notificationDataEntity = await this.notificationDataRepository.GetAsync( partitionKey : NotificationDataTableNames.SentNotificationsPartition, rowKey : messageContent.NotificationId); // If notification is already marked complete, then there is nothing left to do for the data queue trigger. if (!notificationDataEntity.IsCompleted()) { string orchestrationStatus = string.Empty; if (notificationDataEntity.Status.Equals(NotificationStatus.Canceling.ToString())) { orchestrationStatus = await this.updateNotificationDataService.GetOrchestrationStatusAsync(notificationDataEntity.FunctionInstancePayload); } // Get all of the result counts (Successes, Failures, etc.) from the Sent Notification Data. var aggregatedSentNotificationDataResults = await this.aggregateSentNotificationDataService .AggregateSentNotificationDataResultsAsync(messageContent.NotificationId, log); // Use these counts to update the Notification Data accordingly. var notificationDataEntityUpdate = await this.updateNotificationDataService .UpdateNotificationDataAsync( notificationId : messageContent.NotificationId, orchestrationStatus : orchestrationStatus, shouldForceCompleteNotification : messageContent.ForceMessageComplete, totalExpectedNotificationCount : notificationDataEntity.TotalMessageCount, aggregatedSentNotificationDataResults : aggregatedSentNotificationDataResults, log : log); // If the notification is still not in a completed state, then requeue the Data Queue trigger // message with a delay in order to aggregate the results again. if (!notificationDataEntityUpdate.IsCompleted()) { // Requeue data aggregation trigger message with a delay to calculate the totals again. var dataQueueTriggerMessage = new DataQueueMessageContent { NotificationId = messageContent.NotificationId, ForceMessageComplete = false, }; var dataQueueTriggerMessageDelayInSeconds = DateTime.UtcNow <= notificationDataEntity.SendingStartedDate + TimeSpan.FromMinutes(CompanyCommunicatorDataFunction.TenMinutes) ? this.firstTenMinutesRequeueMessageDelayInSeconds : this.requeueMessageDelayInSeconds; await this.dataQueue.SendDelayedAsync(dataQueueTriggerMessage, dataQueueTriggerMessageDelayInSeconds); } } }
public async Task SendDataAggregationQueueMessageAsync( [ActivityTrigger] string notificationId) { var dataQueueMessageContent = new DataQueueMessageContent { NotificationId = notificationId, ForceMessageComplete = false, }; await this.dataQueue.SendDelayedAsync( dataQueueMessageContent, this.firstDataAggregationMessageDelayInSeconds); }
public async Task <IActionResult> CreateSentNotificationAsync( [FromBody] DraftNotification draftNotification) { if (draftNotification == null) { throw new ArgumentNullException(nameof(draftNotification)); } // TODO: double-check it // draftNotification.Buttons = this.GetButtonTrackingUrl(draftNotification); var draftNotificationDataEntity = await this.notificationDataRepository.GetAsync( NotificationDataTableNames.DraftNotificationsPartition, draftNotification.Id); if (draftNotificationDataEntity == null) { return(this.NotFound($"Draft notification, Id: {draftNotification.Id}, could not be found.")); } var newSentNotificationId = await this.notificationDataRepository.MoveDraftToSentPartitionAsync(draftNotificationDataEntity); // Ensure the data table needed by the Azure Functions to send the notifications exist in Azure storage. await this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(); // Update user app id if proactive installation is enabled. await this.UpdateUserAppIdAsync(); var prepareToSendQueueMessageContent = new PrepareToSendQueueMessageContent { NotificationId = newSentNotificationId, }; await this.prepareToSendQueue.SendAsync(prepareToSendQueueMessageContent); // Send a "force complete" message to the data queue with a delay to ensure that // the notification will be marked as complete no matter the counts var forceCompleteDataQueueMessageContent = new DataQueueMessageContent { NotificationId = newSentNotificationId, ForceMessageComplete = true, }; await this.dataQueue.SendDelayedAsync( forceCompleteDataQueueMessageContent, this.forceCompleteMessageDelayInSeconds); return(this.Ok()); }
public async Task <IActionResult> CreateSentNotificationAsync( [FromBody] DraftNotification draftNotification) { var draftNotificationDataEntity = await this.notificationDataRepository.GetAsync( NotificationDataTableNames.DraftNotificationsPartition, draftNotification.Id); if (draftNotificationDataEntity == null) { return(this.NotFound($"Draft notification, Id: {draftNotification.Id}, could not be found.")); } var newSentNotificationId = await this.notificationDataRepository.MoveDraftToSentPartitionAsync(draftNotificationDataEntity); // Ensure the data tables needed by the Azure Functions to send the notifications exist in Azure storage. await Task.WhenAll( this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(), this.sendBatchesDataRepository.EnsureSendBatchesDataTableExistsAsync()); var prepareToSendQueueMessageContent = new PrepareToSendQueueMessageContent { NotificationId = newSentNotificationId, }; await this.prepareToSendQueue.SendAsync(prepareToSendQueueMessageContent); // Send a "force complete" message to the data queue with a delay to ensure that // the notification will be marked as complete no matter the counts var forceCompleteDataQueueMessageContent = new DataQueueMessageContent { NotificationId = newSentNotificationId, ForceMessageComplete = true, }; await this.dataQueue.SendDelayedAsync( forceCompleteDataQueueMessageContent, this.forceCompleteMessageDelayInSeconds); return(this.Ok()); }
private async void SendNotification(string id) { var draftNotificationDataEntity = await this.notificationDataRepository.GetAsync( NotificationDataTableNames.DraftNotificationsPartition, id); if (draftNotificationDataEntity == null) { this.smslogger.LogError($"Draft notification, Id: {id}, could not be found."); } else { var newSentNotificationId = await this.notificationDataRepository.MoveDraftToSentPartitionAsync(draftNotificationDataEntity); // Ensure the data table needed by the Azure Functions to send the notifications exist in Azure storage. await this.sentNotificationDataRepository.EnsureSentNotificationDataTableExistsAsync(); var prepareToSendQueueMessageContent = new PrepareToSendQueueMessageContent { NotificationId = newSentNotificationId, }; await this.prepareToSendQueue.SendAsync(prepareToSendQueueMessageContent); // Send a "force complete" message to the data queue with a delay to ensure that // the notification will be marked as complete no matter the counts. var forceCompleteDataQueueMessageContent = new DataQueueMessageContent { NotificationId = newSentNotificationId, ForceMessageComplete = true, }; await this.dataQueue.SendDelayedAsync( forceCompleteDataQueueMessageContent, this.forceCompleteMessageDelayInSeconds); } }