-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from dr-o-ne/issue_32
Fix for issue #32
- Loading branch information
Showing
4 changed files
with
65 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace QueryTree.Services | ||
{ | ||
public sealed class EmailSenderService : IEmailSenderService | ||
{ | ||
private const int TimeoutInSeconds = 60; | ||
private readonly object _locker = new object(); | ||
private readonly Dictionary<int, DateTime> _messageDeliveryTime = new Dictionary<int, DateTime>(); | ||
|
||
public bool TrySetDelivered(int messageId) | ||
{ | ||
|
||
DateTime deliveredTime; | ||
if (!_messageDeliveryTime.TryGetValue(messageId, out deliveredTime) || deliveredTime.AddSeconds(TimeoutInSeconds) <= DateTime.UtcNow) | ||
{ | ||
lock(_locker) | ||
{ | ||
if (!_messageDeliveryTime.TryGetValue(messageId, out deliveredTime) || deliveredTime.AddSeconds(TimeoutInSeconds) <= DateTime.UtcNow) | ||
{ | ||
_messageDeliveryTime[messageId] = DateTime.UtcNow; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace QueryTree.Services | ||
{ | ||
public interface IEmailSenderService | ||
{ | ||
bool TrySetDelivered(int messageId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters