Interface IKickRequestService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Service interface for kick request operations. Provides async methods for persisting, deleting, and fetching kick requests.
public interface IKickRequestService
Remarks
Write operations (Persist*, Delete*) in this service use execution strategies to ensure transient database failures are automatically retried according to the retry policy configured on the DbContext. This is critical because SaveChangesAsync and ExecuteSqlRawAsync do not automatically retry on transient failures without an execution strategy wrapper. BaseService provides execution wrappers for retry and centralized exception mapping; explicit transactions are used only when a write requires multiple database statements.
All methods return DatabaseResult or DatabaseResult<T> to provide structured error information through the DatabaseException system, helping distinguish between: - Validation failures (invalid parameters) - Database errors (connection issues, constraint violations, timeouts) - Entity not found errors - Unexpected runtime errors
Kick requests are used to forcefully disconnect accounts from active sessions.
Methods
DeleteAsync(string, CancellationToken)
Deletes all kick requests for the specified account.
Task<DatabaseResult<int>> DeleteAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringAccount name whose kick requests will be deleted.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<int>>
A DatabaseResult<T> containing the number of kick requests deleted on success, or a DatabaseException on failure.
Remarks
This is an idempotent cleanup operation. Unlike entity delete methods, this method does NOT throw DatabaseEntityNotFoundException when no records exist. Instead, it returns 0 rows deleted. This design supports safe concurrent cleanup where multiple callers may attempt to delete the same records.
Uses ExecuteSqlRawAsync with execution strategy wrapping to ensure transient database failures are automatically retried.
FetchAsync(KickRequestPollQuery, CancellationToken)
Reads one page of kick requests for a game server's poll, on the database's clock.
Task<DatabaseResult<KickRequestPage>> FetchAsync(KickRequestPollQuery query, CancellationToken cancellationToken = default)
Parameters
queryKickRequestPollQueryWhere to read from and what to skip, built by BuildQuery(int, double).
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<KickRequestPage>>
The page — requests stamped at or after the start and not already handled, in
(time_created, id)order — with the database clock taken before it was read and the start it read from; or a DatabaseException on failure.
Remarks
The reader keeps its place with KickRequestReadWindow, which reads a commit window (PollCommitWindowSeconds) behind what it has settled and skips what it has handled, so a request that commits after a later-stamped one is still read. A first read (no FromUtc) starts FirstReadLookbackSeconds before the database's "now". Each request carries its account's last login (AccountLastLogin), read in the same query, so the caller needs no per-kick lookup to tell a stale kick.
HasPendingAsync(string, CancellationToken)
Checks whether a pending kick request exists for the specified account.
Task<DatabaseResult<bool>> HasPendingAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringAccount name to check.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<bool>>
A DatabaseResult<T> containing
trueif a pending kick request exists,falseotherwise, or a DatabaseException on failure.
Remarks
A request is pending for a bounded time after its stamp, measured by the database's clock, which wrote the stamp; never by the calling process's.
PersistAsync(string, CancellationToken)
Persists a kick request for the specified account.
Task<DatabaseResult> PersistAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringAccount name to kick.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult>
A DatabaseResult indicating success or containing a DatabaseException on failure.
Remarks
Uses SaveChangesAsync with execution strategy wrapping to ensure transient database failures are automatically retried. Creates new kick request with current UTC timestamp.