Class EmailQueueDrainService
- Namespace
- FishMMO.ControlPanel.Services
- Assembly
- FishMMO-ControlPanel.dll
Delivers the outbound email queue. This is the process that turns a queued row into a message in somebody's inbox.
public sealed class EmailQueueDrainService : BackgroundService, IHostedService, IDisposable
- Inheritance
-
EmailQueueDrainService
- Implements
- Inherited Members
Remarks
This used to live in the LoginServer, driven from a Unity frame callback: a timer
accumulated deltaTime, one message went out every ten seconds, the send was
fire-and-forget with a flag to stop two overlapping, and the blocking network call to the
relay happened on a game server's tick. It worked, and none of it belonged there —
sending mail was paced by frame time, and a relay that took its time held up a loop whose
job is players. This is an ASP.NET Core host with a thread pool, real asynchrony and an
existing BackgroundService pattern, so the work moves here and the game
server goes back to only enqueueing.
The queue is the coordination, not this class. DequeueNextAsync claims a
row with FOR UPDATE SKIP LOCKED, so a panel and a login server — or two panels —
racing for the same row is already handled: each gets a different row or nothing. Nothing
here assumes it is the only drain, which is what makes the migration safe to do one
process at a time.
The verification stamp is conditional, and that condition is the reason
EmailKind exists. After a successful send the old drain always called
PersistVerificationEmailSentAsync, which stamps verification_email_sent_at.
That column once ended the grace period an unverified account signed in under; there is no
grace period any more, and it now records only when a verification code last reached the
player — which staff read on the account page and in the ticket three wrong codes open. A
stamp after a password reset would tell them a code arrived when none did. So the stamp
still follows the row's kind, and the kind is a column rather than a guess at the subject line.
Nothing here is audited. The audit log records what an operator did; a background loop delivering mail is not an operator action, and writing one audit row per verification email would bury the rows that record a person doing something.
Constructors
EmailQueueDrainService(IServiceScopeFactory, ISmtpSender, IConfiguration, ILogger<EmailQueueDrainService>)
Creates the service.
public EmailQueueDrainService(IServiceScopeFactory scopeFactory, ISmtpSender sender, IConfiguration configuration, ILogger<EmailQueueDrainService> log)
Parameters
scopeFactoryIServiceScopeFactorysenderISmtpSenderconfigurationIConfigurationlogILogger<EmailQueueDrainService>
Methods
ExecuteAsync(CancellationToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
Remarks
See Worker Services in .NET for implementation guidelines.