add WorkerOptions.
- bind IntervalInMin with worker task delay
This commit is contained in:
parent
187f4a42fc
commit
b5cd42b6fa
19
EnvelopeGenerator.Finalizer/Models/WorkerOptions.cs
Normal file
19
EnvelopeGenerator.Finalizer/Models/WorkerOptions.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
namespace EnvelopeGenerator.Finalizer.Models;
|
||||||
|
|
||||||
|
public class WorkerOptions
|
||||||
|
{
|
||||||
|
private double _intervalInMin = 1.0;
|
||||||
|
|
||||||
|
public double IntervalInMin {
|
||||||
|
get => _intervalInMin;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_intervalInMin = value;
|
||||||
|
IntervalInMillisecond = Min2Millisecond(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int IntervalInMillisecond { get; private set; } = Min2Millisecond(1.0);
|
||||||
|
|
||||||
|
private static int Min2Millisecond(double min) => Convert.ToInt32(Math.Round(min * 60 * 1000));
|
||||||
|
}
|
||||||
@ -34,7 +34,10 @@ try
|
|||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(file => config.AddJsonFile(file, true, true));
|
.ForEach(file => config.AddJsonFile(file, true, true));
|
||||||
|
|
||||||
|
#region Worker
|
||||||
builder.Services.AddHostedService<Worker>();
|
builder.Services.AddHostedService<Worker>();
|
||||||
|
builder.Services.Configure<WorkerOptions>(config.GetSection("Worker"));
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Add DB Context, EG Inf. and Services
|
#region Add DB Context, EG Inf. and Services
|
||||||
var cnnStrName = "Default";
|
var cnnStrName = "Default";
|
||||||
|
|||||||
@ -1,12 +1,18 @@
|
|||||||
|
using EnvelopeGenerator.Finalizer.Models;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Finalizer
|
namespace EnvelopeGenerator.Finalizer
|
||||||
{
|
{
|
||||||
public class Worker : BackgroundService
|
public class Worker : BackgroundService
|
||||||
{
|
{
|
||||||
private readonly ILogger<Worker> _logger;
|
private readonly ILogger<Worker> _logger;
|
||||||
|
|
||||||
public Worker(ILogger<Worker> logger)
|
private readonly WorkerOptions _options;
|
||||||
|
|
||||||
|
public Worker(ILogger<Worker> logger, IOptions<WorkerOptions> workerOptions)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_options = workerOptions.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@ -17,7 +23,7 @@ namespace EnvelopeGenerator.Finalizer
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||||
}
|
}
|
||||||
await Task.Delay(1000, stoppingToken);
|
await Task.Delay(_options.IntervalInMillisecond, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
EnvelopeGenerator.Finalizer/appsettings.Worker.Database.json
Normal file
21
EnvelopeGenerator.Finalizer/appsettings.Worker.Database.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UseDbMigration": false,
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"Default": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;",
|
||||||
|
"DbMigrationTest": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM_DATA_MIGR_TEST;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;"
|
||||||
|
},
|
||||||
|
"DbTriggerParams": {
|
||||||
|
"Envelope": [ "TBSIG_ENVELOPE_AFT_INS" ],
|
||||||
|
"History": [ "TBSIG_ENVELOPE_HISTORY_AFT_INS" ],
|
||||||
|
"EmailOut": [ "TBEMLP_EMAIL_OUT_AFT_INS", "TBEMLP_EMAIL_OUT_AFT_UPD" ],
|
||||||
|
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
||||||
|
"Receiver": [],
|
||||||
|
"EmailTemplate": [ "TBSIG_EMAIL_TEMPLATE_AFT_UPD" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
EnvelopeGenerator.Finalizer/appsettings.Worker.Logging.json
Normal file
81
EnvelopeGenerator.Finalizer/appsettings.Worker.Logging.json
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Verbose",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"System": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "Console",
|
||||||
|
"Args": {
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "E:/LogFiles/Digital Data/signFlow.Finalizer/log.Verbose-.txt",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"restrictedToMinimumLevel": "Verbose",
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "E:/LogFiles/Digital Data/signFlow.Finalizer/log.Debug-.txt",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"restrictedToMinimumLevel": "Debug",
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "E:/LogFiles/Digital Data/signFlow.Finalizer/log.Info-.txt",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"restrictedToMinimumLevel": "Information",
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "E:/LogFiles/Digital Data/signFlow.Finalizer/log.Warning-.txt",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"restrictedToMinimumLevel": "Warning",
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "E:/LogFiles/Digital Data/signFlow.Finalizer/log.Error-.txt",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"restrictedToMinimumLevel": "Error",
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "E:/LogFiles/Digital Data/signFlow.Finalizer/log.Fatal-.txt",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"restrictedToMinimumLevel": "Fatal",
|
||||||
|
"retainedFileCountLimit": 30,
|
||||||
|
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"IgnoredLabels": {
|
||||||
|
"Label": [
|
||||||
|
"Date",
|
||||||
|
"Datum",
|
||||||
|
"ZIP",
|
||||||
|
"PLZ",
|
||||||
|
"Place",
|
||||||
|
"Ort",
|
||||||
|
"Position",
|
||||||
|
"Stellung"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
5
EnvelopeGenerator.Finalizer/appsettings.Worker.json
Normal file
5
EnvelopeGenerator.Finalizer/appsettings.Worker.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Worker": {
|
||||||
|
"IntervalInMin": 0.01666666666
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user