Skip to content

Commit

Permalink
Fix Dave review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuvaraj committed Sep 18, 2024
1 parent fce092a commit dece0c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
13 changes: 7 additions & 6 deletions NotificationSystem/SendModeratorEmail.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
using Amazon;
using Amazon.SimpleEmail;
using RateLimiter;
using ComposableAsync;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Table;
Expand All @@ -7,16 +11,14 @@
using Microsoft.Extensions.Logging;
using NotificationSystem.Template;
using NotificationSystem.Utilities;
using Amazon;
using Amazon.SimpleEmail;
using RateLimiter;
using ComposableAsync;

namespace NotificationSystem
{
[StorageAccount("OrcaNotificationStorageSetting")]
public static class SendModeratorEmail
{
static int SendRate = 14;

[FunctionName("SendModeratorEmail")]
public static async Task Run(
[CosmosDBTrigger(
Expand Down Expand Up @@ -56,10 +58,9 @@ public static async Task Run(
return;
}

// TODO: make better email
string body = EmailTemplate.GetModeratorEmailBody(documentTimeStamp, location);

var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(14, TimeSpan.FromSeconds(1));
var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(SendRate, TimeSpan.FromSeconds(1));
var aws = new AmazonSimpleEmailServiceClient(RegionEndpoint.USWest2);
log.LogInformation("Retrieving email list and sending notifications");
foreach (var emailEntity in EmailHelpers.GetEmailEntities(cloudTable, "Moderator"))
Expand Down
14 changes: 8 additions & 6 deletions NotificationSystem/SendSubscriberEmail.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
using Amazon;
using Amazon.SimpleEmail;
using RateLimiter;
using ComposableAsync;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -10,17 +14,15 @@
using Newtonsoft.Json.Linq;
using NotificationSystem.Template;
using NotificationSystem.Utilities;
using Amazon;
using Amazon.SimpleEmail;
using RateLimiter;
using ComposableAsync;

namespace NotificationSystem
{
[StorageAccount("OrcaNotificationStorageSetting")]
public static class SendSubscriberEmail
{
[FunctionName("SendSubscriberEmail")]
static int SendRate = 14;

[FunctionName("SendSubscriberEmail")]
// TODO: change timer to once per hour (0 0 * * * *)
public static async Task Run(
[TimerTrigger("0 */1 * * * *")] TimerInfo myTimer,
Expand All @@ -40,7 +42,7 @@ public static async Task Run(
log.LogInformation("Creating email message");
var body = await CreateBody(cloudQueue);

var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(14, TimeSpan.FromSeconds(1));
var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(SendRate, TimeSpan.FromSeconds(1));
var aws = new AmazonSimpleEmailServiceClient(RegionEndpoint.USWest2);
log.LogInformation("Retrieving email list and sending notifications");
foreach (var emailEntity in EmailHelpers.GetEmailEntities(cloudTable, "Subscriber"))
Expand Down
6 changes: 3 additions & 3 deletions NotificationSystem/Utilities/EmailHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public static IEnumerable<EmailEntity> GetEmailEntities(CloudTable cloudTable, s

public static SendEmailRequest CreateEmail(string from, string to, string subject, string body)
{
var email = new SendEmailRequest();
email.Source = from;
email.Destination = new Destination(new List<string> { to });
var email = new SendEmailRequest();
email.Source = from;
email.Destination = new Destination(new List<string> { to });
//Create message and attach to email request.
Message message = new Message();
message.Subject = new Content(subject);
Expand Down

0 comments on commit dece0c7

Please sign in to comment.