Skip to content

Commit

Permalink
Merge pull request #565 from SharebookBR/fix-jobs
Browse files Browse the repository at this point in the history
Fix mailSender job
  • Loading branch information
raffacabofrio authored Jul 20, 2024
2 parents 51d0299 + db34707 commit 487ac0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions ShareBook/ShareBook.Service/Email/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,16 @@ public async Task<IList<string>> ProcessBounceMessagesAsync()
return null;
}

public async Task<IList<MailBounce>> GetBouncesAsync(IList<string> emails)
public async Task<IList<MailBounce>> GetBouncesAsync(string email)
{
return await _ctx.MailBounces.Where(m => emails.Contains(m.Email)).ToListAsync();
return await _ctx.MailBounces.Where(m => email.Contains(m.Email)).ToListAsync();
}

public bool IsBounce(string email, IList<MailBounce> bounces)
public async Task<bool> IsBounceAsync(string email)
{
var bounces = await GetBouncesAsync(email);


var hardBounces = bounces.Where(b => !b.IsSoft).ToList();
var softBounces = bounces.Where(b => b.IsSoft && b.CreationDate > DateTime.Now.AddDays(-1)).ToList();

Expand Down
4 changes: 2 additions & 2 deletions ShareBook/ShareBook.Service/Email/IEmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IEmailService
Task TestAsync(string email, string name);

Task<IList<string>> ProcessBounceMessagesAsync();
Task<IList<MailBounce>> GetBouncesAsync(IList<string> emails);
bool IsBounce(string email, IList<MailBounce> bounces);
Task<IList<MailBounce>> GetBouncesAsync(string email);
Task<bool> IsBounceAsync(string email);
}
}
3 changes: 1 addition & 2 deletions ShareBook/Sharebook.Jobs/Jobs/7 - MailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ private async Task<int> SendEmailAsync(SharebookMessage<MailSenderbody> sqsMessa
var copyAdmins = sqsMessage.Body.CopyAdmins;

var emails = destinations.Select(x => x.Email).ToList();
var bounces = await _emailService.GetBouncesAsync(emails);

foreach (var destination in destinations)
{
try {
if (_emailService.IsBounce(destination.Email, bounces))
if (await _emailService.IsBounceAsync(destination.Email))
{
_log.Add($"Não enviei email para {destination.Email} porque está em estado de BOUNCE.");
continue;
Expand Down

0 comments on commit 487ac0f

Please sign in to comment.