Class MaintenanceAdvanceService
- Namespace
- FishMMO.ControlPanel.Services
- Assembly
- FishMMO-ControlPanel.dll
Advances maintenance windows on a timer, so their record does not depend on somebody having the page open.
public sealed class MaintenanceAdvanceService : BackgroundService, IHostedService, IDisposable
- Inheritance
-
MaintenanceAdvanceService
- Implements
- Inherited Members
Remarks
Starting a window is already complete when it returns: each target's own row carries a lock and an absolute deadline, and the server counts down to it inside its own process. None of that needs this service, and nothing here is required for a shard to stop on time. What needs it is everything the panel knows afterwards.
Two things go wrong without it. The smaller one is that statuses stay stale: every read advances the record, so with nobody looking, a window whose servers stopped an hour ago still reads "Draining" until the next person opens the page. The shard went down on time and only the bookkeeping is late — but an operator checking whether last night's maintenance finished is reading exactly that bookkeeping.
The larger one is the retry. The plan is committed before any server is touched, so a panel that dies mid-actuation leaves a visible half-written window rather than a locked shard with no record — and AdvanceAsync(CancellationToken) is what finishes those writes. Left to a reader, a target whose deadline was never written sits unwritten until somebody happens to look, and a server the operator believes is draining is in fact still open and still taking players.
A failed pass is logged and the timer continues. Refusing to serve the panel because one advance could not reach the database would turn a transient fault into an outage on the one surface an operator opens during an incident.
Constructors
MaintenanceAdvanceService(IServiceScopeFactory, ILogger<MaintenanceAdvanceService>)
Creates the service.
public MaintenanceAdvanceService(IServiceScopeFactory scopeFactory, ILogger<MaintenanceAdvanceService> log)
Parameters
scopeFactoryIServiceScopeFactoryFactory for the scope each pass resolves its service from.
logILogger<MaintenanceAdvanceService>The log to report failures to.
Methods
ExecuteAsync(CancellationToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
Remarks
See Worker Services in .NET for implementation guidelines.