Contact: mail via achtergrondservice met claim, backoff en maximum (CMS-U5)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,16 @@ public interface IContactRepository
|
||||
|
||||
Task<ContactSettings?> GetSettingsAsync(CancellationToken cancellationToken);
|
||||
void Add(ContactSettings settings);
|
||||
|
||||
// ---- background mail ----
|
||||
|
||||
/// <summary>
|
||||
/// Unread (<c>New</c>) messages whose mail is due: pending or failed, fewer than <paramref name="maxAttempts"/>
|
||||
/// attempts, and no next-attempt time in the future. Oldest first. Read, archived and spam messages are never mailed
|
||||
/// automatically.
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<ContactMessage>> GetDueForMailAsync(
|
||||
string siteId, DateTimeOffset now, int maxAttempts, int take, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public class ContactRepository(ContactDbContext context) : IContactRepository
|
||||
@@ -94,6 +104,18 @@ public class ContactRepository(ContactDbContext context) : IContactRepository
|
||||
|
||||
public void Add(ContactSettings settings) => context.ContactSettings.Add(settings);
|
||||
|
||||
public async Task<IReadOnlyList<ContactMessage>> GetDueForMailAsync(
|
||||
string siteId, DateTimeOffset now, int maxAttempts, int take, CancellationToken cancellationToken)
|
||||
=> await context.ContactMessages
|
||||
.Where(m => m.SiteId == siteId
|
||||
&& m.Status == ContactMessageStatus.New
|
||||
&& (m.MailStatus == ContactMailStatus.Pending || m.MailStatus == ContactMailStatus.Failed)
|
||||
&& m.MailAttempts < maxAttempts
|
||||
&& (m.NextMailAttemptAt == null || m.NextMailAttemptAt <= now))
|
||||
.OrderBy(m => m.ReceivedAt)
|
||||
.Take(take)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
public async Task<int> DeleteExpiredMessagesAsync(DateTimeOffset now, CancellationToken cancellationToken)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
Reference in New Issue
Block a user