Interface ISmsQueueService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Service for the outbound SMS queue. Messages are enqueued by the application and delivered asynchronously by a background sender. The method-for-method twin of IEmailQueueService.
public interface ISmsQueueService
Remarks
No SMS provider exists yet; the sender that drains this queue only logs.
Methods
DequeueNextAsync(string, CancellationToken)
Atomically claims and dequeues the next pending message using
FOR UPDATE SKIP LOCKED. Safe for concurrent senders. Returns a NOT_FOUND failure
when the queue is empty.
Task<DatabaseResult<SmsQueueData>> DequeueNextAsync(string claimedBy, CancellationToken cancellationToken = default)
Parameters
claimedBystringIdentifier of the claiming server (e.g. server name).
cancellationTokenCancellationTokenCancellation token.
Returns
EnqueueAsync(string, string, string, SmsKind, CancellationToken)
Enqueues a text message for asynchronous delivery.
Task<DatabaseResult> EnqueueAsync(string recipientPhone, string recipientUsername, string body, SmsKind kind = SmsKind.Verification, CancellationToken cancellationToken = default)
Parameters
recipientPhonestringRecipient number in E.164 form:
+then up to 15 digits.recipientUsernamestringAssociated account username.
bodystringMessage text, at most 480 characters.
kindSmsKindWhat the message is for. Defaults to Verification, the column default.
cancellationTokenCancellationTokenCancellation token.
Returns
HasPendingForUserAsync(string, SmsKind?, CancellationToken)
Returns true if the specified user already has an unsent message of
kind in the queue. Prevents duplicate messages piling up.
Task<DatabaseResult<bool>> HasPendingForUserAsync(string recipientUsername, SmsKind? kind = null, CancellationToken cancellationToken = default)
Parameters
recipientUsernamestringkindSmsKind?cancellationTokenCancellationToken
Returns
Remarks
Pass the kind you are about to send. A blind check answers a different question: a pending notification would suppress the verification code a player is waiting for. Null means any kind, and is almost never what a caller wants.
MarkFailedAsync(long, string, int, CancellationToken)
Marks a delivery attempt as failed and increments the attempt counter.
Task<DatabaseResult> MarkFailedAsync(long id, string error, int maxAttempts = 5, CancellationToken cancellationToken = default)
Parameters
idlongerrorstringmaxAttemptsintcancellationTokenCancellationToken
Returns
Remarks
While attempts remain the claim is released, which is what puts the message back in
line for another sender to pick up. Once maxAttempts is reached the
claim is kept, which takes the message out of circulation and leaves it in the queue
with its error for an operator to investigate or retry by hand.
MarkSentAsync(long, CancellationToken)
Marks a message as successfully sent.
Task<DatabaseResult> MarkSentAsync(long id, CancellationToken cancellationToken = default)
Parameters
idlongcancellationTokenCancellationToken