Class PartyUpdateService
Service for managing party update notifications in the database. Tracks when parties have been modified so clients can poll for changes. Implements execution strategies for automatic retry on transient database failures. Returns DatabaseResult for consistent, safe error handling.
public sealed class PartyUpdateService : BaseService<PartyUpdateEntity>, IPartyUpdateService
- Inheritance
-
PartyUpdateService
- Implements
- Inherited Members
Remarks
This service manages party update tracking including:
- Recording party updates with atomic UPSERT operations
- Fetching parties modified since a given timestamp
- Cleaning up update records for deleted parties
Database operations are executed via the BaseService execution wrappers for:
- Automatic transient failure retry
- Centralized exception handling and mapping
- Consistent DatabaseResult pattern
The update tracking pattern allows clients to efficiently poll for changes without needing to re-fetch all party data on each request.
Constructors
PartyUpdateService(INpgsqlDbContextFactory)
Initializes a new instance of PartyUpdateService.
public PartyUpdateService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactoryDbContext factory for creating contexts.
Exceptions
- ArgumentNullException
Thrown when dbContextFactory is null.
Methods
DeleteAsync(long, CancellationToken)
Deletes all update records for a party.
public Task<DatabaseResult<int>> DeleteAsync(long partyId, CancellationToken cancellationToken = default)
Parameters
partyIdlongParty ID.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<int>>
A DatabaseResult<T> containing the number of records 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 a single-statement DELETE.
FetchAsync(List<long>, DateTime, CancellationToken)
Fetches party update records for specified parties updated since last fetch.
public Task<DatabaseResult<List<PartyUpdateData>>> FetchAsync(List<long> partyIds, DateTime lastFetch, CancellationToken cancellationToken = default)
Parameters
partyIdsList<long>List of party IDs to check.
lastFetchDateTimeTimestamp to compare against.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<List<PartyUpdateData>>>
A DatabaseResult<T> containing the list of party update data on success, or a DatabaseException on failure.
Remarks
Filters by both timestamp and party ID list.
PersistAsync(long, CancellationToken)
Saves or updates the last update timestamp for a party using atomic UPSERT.
public Task<DatabaseResult> PersistAsync(long partyId, CancellationToken cancellationToken = default)
Parameters
partyIdlongParty ID.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult>
A DatabaseResult indicating success or containing a DatabaseException on failure.
Remarks
Uses a single-statement PostgreSQL INSERT ... ON CONFLICT DO UPDATE with a conditional
update to avoid regressing last_update.