Class QueueBoardService
Reads the email and group finder queues for the operator board, and releases a stuck email back into its queue.
public sealed class QueueBoardService : BaseService<EmailQueueEntity>, IQueueBoardService
- Inheritance
-
QueueBoardService
- Implements
- Inherited Members
Remarks
EF throughout for the reads, one parameterized statement for the single write. See IQueueBoardService for why this is a service of its own and why it cannot empty anything.
The counts are four separate COUNT statements rather than one grouped scan.
A single GROUP BY over a computed state expression would be one round trip, but the
expression is a nested conditional and this project is pinned to EF Core 5 (see the
csproj: netstandard2.1 for Unity), whose GROUP BY translation gives up on shapes like
that and falls back to evaluating them in memory over the whole table. On the one
page whose job is to notice a queue that has grown without bound, silently reading the
entire queue into the panel to count it is the worst available failure. Four counts
against the table's existing (sent_at, created_at) and (claimed_at, sent_at)
indexes are cheap, obviously correct, and cannot degrade into that.
Constructors
QueueBoardService(INpgsqlDbContextFactory)
public QueueBoardService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Methods
FetchEmailQueueAsync(EmailQueueState?, string, int, int, CancellationToken)
One page of the outbound email queue, with per-state counts and the age of the oldest message nothing has picked up.
public Task<DatabaseResult<EmailQueuePage>> FetchEmailQueueAsync(EmailQueueState? state, string search, int page, int pageSize, CancellationToken cancellationToken = default)
Parameters
stateEmailQueueState?Filter to one state, or null for any. See EmailQueueState.
searchstringCase-insensitive substring of the recipient address or the account name, or null for all. For the question "did this player's mail ever go out", which is the other reason somebody opens this page.
pageint1-based page number. Values below 1 are treated as 1.
pageSizeintRows per page. Clamped by the service.
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
The counts and the two oldest-row timestamps are computed over the whole table and are
unaffected by state, search or the page: they are
the alarm, and an alarm that changed when the operator narrowed a filter would be
worse than none.
FetchGroupFinderQueueAsync(int?, int, int, CancellationToken)
One page of the group finder queue, with per-state counts.
public Task<DatabaseResult<GroupFinderQueuePage>> FetchGroupFinderQueueAsync(int? status, int page, int pageSize, CancellationToken cancellationToken = default)
Parameters
statusint?Filter by GroupFinderQueueStatus, or null for any.
pageint1-based page number. Values below 1 are treated as 1.
pageSizeintRows per page. Clamped by the service.
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Read-only, and there is no companion write. See the remarks on this interface.
FetchSmsQueueAsync(EmailQueueState?, string, int, int, CancellationToken)
One page of the outbound SMS queue, with per-state counts and the age of the oldest message nothing has picked up. The twin of FetchEmailQueueAsync(EmailQueueState?, string, int, int, CancellationToken).
public Task<DatabaseResult<SmsQueuePage>> FetchSmsQueueAsync(EmailQueueState? state, string search, int page, int pageSize, CancellationToken cancellationToken = default)
Parameters
stateEmailQueueState?Filter to one state, or null for any.
searchstringAccount-name substring, or a whole phone number. Null for all.
pageint1-based page number. Values below 1 are treated as 1.
pageSizeintRows per page. Clamped by the service.
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
The counts and ages are over the whole table, as the email read's are. The body is never projected: a verification text is a one-time code.
The search matches a phone number whole, never in part. The account name is a substring match as on the email board, but the number is compared after stripping spaces, dashes, dots and brackets, and only for equality. The page shows numbers masked to their last four digits; a substring search would let anyone with the page recover a masked number a digit at a time. An operator who already holds the number can still ask "did a code go to this phone".
RetryEmailAsync(long, CancellationToken)
Puts a claimed email back in the queue by releasing the claim on it.
public Task<DatabaseResult<EmailRetryResult>> RetryEmailAsync(long id, CancellationToken cancellationToken = default)
Parameters
idlongThe email queue row.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<EmailRetryResult>>
What happened, including a refusal. A failure result with NotFound when no such row exists.
Remarks
This is the only thing "retry" can mean here, and it works because of a defect.
EmailQueueService.MarkFailedAsync increments attempts and records
last_error but never clears claimed_at, and DequeueNextAsync only
ever selects rows where claimed_at IS NULL. So a failed delivery is not retried
by anything, ever, despite the entity and the interface both documenting a retry limit
— the maxAttempts parameter is not read. Until that is fixed in the login
server, releasing the claim from here is the only way a failed verification email is
ever sent, and every row it leaves behind is an account that cannot finish registering.
A row merely claimed, with no error, is retryable too. A login server that died between claiming a message and reporting on it leaves exactly that, and it is stuck just as permanently and far more quietly than a failure — nothing wrote an error, because nothing got far enough to have one. Refusing to unstick it would leave the most likely form of this outage with no remedy on the page built to surface it.
What it does not do: it does not send anything — delivery is the login server's,
and the row simply becomes eligible again on that server's next pass — and it does not
reset attempts or clear last_error. Those are the evidence of what went
wrong, and an operator pressing retry a second time needs to see that the first one
came back.
Two rows are refused rather than acted on, and both come back as a successful result carrying Refusal: a message already sent, and a message still unclaimed. Retrying the first would re-send mail somebody already acted on; "retrying" the second would change nothing, because it is already in line and the thing it is waiting for is a login server. Neither is a database failure, and both are worth telling the operator precisely.
The read, the guard and the write are one statement, so a login server claiming the same row at the same moment produces one winner rather than a claim released out from under a delivery already in flight.
RetrySmsAsync(long, CancellationToken)
Puts a claimed text message back in the queue by releasing the claim on it. The twin of RetryEmailAsync(long, CancellationToken), with the same single-statement guard and the same two refusals (already sent; never claimed).
public Task<DatabaseResult<SmsRetryResult>> RetrySmsAsync(long id, CancellationToken cancellationToken = default)
Parameters
idlongThe SMS queue row.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<SmsRetryResult>>
What happened, including a refusal. A failure result with NotFound when no such row exists.
Remarks
SmsQueueService.MarkFailedAsync releases the claim itself while attempts remain
and keeps it once they are spent, so a row that reads as failed is one the drain has
given up on. Releasing it grants exactly one more attempt: attempts is not reset,
so a further failure gives up again. A claimed row with no error — a drain that died
mid-send — is retryable too.