2.0 KiB
2.0 KiB
applyTo
| applyTo |
|---|
| Fuchs_DataService/** |
Topshelf Instructions
Overview
Fuchs_DataService uses Topshelf 4.x as the Windows Service host. The hosted jobs run inside a PeriodicHostedService (see periodic_service.instructions.md), which is managed by the Topshelf FdsService class.
Structure
FdsMainModule.Main()
└── HostFactory.Run()
└── FdsService : ServiceControl
├── Start() → _hostedService.StartAsync(_cts.Token)
└── Stop() → _cts.Cancel() + _hostedService.StopAsync()
FdsService Rules
FdsServiceowns aCancellationTokenSource _ctsfor cooperative cancellation.FdsServicebuilds theILoggerFactory(viaLoggerFactory.Create(b => b.AddFdsLogging())) and passes it to all job objects.FdsServiceconstructsFdsMfrdirectly:new FdsMfr(loggerFactory.CreateLogger<FdsMfr>(), loggerFactory).FdsServiceconstructsPeriodicHostedServicewith jobs and passesloggerFactory.CreateLogger<PeriodicHostedService>().- Never use the generic
Microsoft.Extensions.Hosting.Host.CreateDefaultBuilderpattern here — Topshelf manages the host lifetime.
Topshelf Configuration
HostFactory.Run(x =>
{
x.Service<FdsService>(s =>
{
s.ConstructUsing(name => new FdsService());
s.WhenStarted((tc, host) => tc.Start(host));
s.WhenStopped((tc, host) => tc.Stop(host));
s.WhenPaused((tc, host) => tc.Stop(host));
s.WhenContinued((tc, host) => tc.Start(host));
});
x.EnablePauseAndContinue();
x.StartAutomatically();
x.RunAsLocalSystem();
x.SetDescription("MFR Data Sync");
x.SetDisplayName("MFR Data Sync");
x.SetServiceName("MFR Data Sync");
});
Dev-Machine Shortcut
On machines named digital-pc or digital-dpc the service runs in-process (console) instead of installing as a Windows Service.
Adding a New Job
Add a new PeriodicJobDefinition in FdsService constructor — see periodic_service.instructions.md.