Table of Contents

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

claimedBy string

Identifier of the claiming server (e.g. server name).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<SmsQueueData>>

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

recipientPhone string

Recipient number in E.164 form: + then up to 15 digits.

recipientUsername string

Associated account username.

body string

Message text, at most 480 characters.

kind SmsKind

What the message is for. Defaults to Verification, the column default.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

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

recipientUsername string
kind SmsKind?
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>

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

id long
error string
maxAttempts int
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

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

id long
cancellationToken CancellationToken

Returns

Task<DatabaseResult>