Fix example
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
}
|
||||
},
|
||||
"EntityFrameworkmigration": {
|
||||
"AutoMigrate": true
|
||||
"AutoMigrate": true
|
||||
},
|
||||
"Server": {
|
||||
"UseCors": true,
|
||||
@@ -64,9 +64,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"SayHelloWorldJob": {
|
||||
"CronExpression": "*/30 * * * * ? *",
|
||||
"Name": "Example Job"
|
||||
"Jobs": {
|
||||
"SayHelloWorldJob": {
|
||||
"CronExpression": "*/30 * * * * ? *",
|
||||
"Name": "Example Job With Specific Name"
|
||||
},
|
||||
"SayHelloWorldWithDefaultNameUsageJob": {
|
||||
"CronExpression": "*/30 * * * * ? *"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.RollingFile" ],
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using GerstITS.Job.Scheduling;
|
||||
using GerstITS.System.Configurations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld.Configurations;
|
||||
|
||||
public class SayHelloWorldWithDefaultNameUsageJobConfiguration : JobSchedulingConfigurationBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SayHelloWorldWithDefaultNameUsageJobConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
var prefix = this.ToConfigurationPrefix();
|
||||
|
||||
Name = configuration.GetValue<string>($"{prefix}:{nameof(Name)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -15,19 +15,14 @@ namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs
|
||||
|
||||
private readonly SayHelloWorldJobConfiguration _configuration;
|
||||
private readonly Stopwatch _stopWatch;
|
||||
private readonly IRepository _repository;
|
||||
private readonly ISystemClock _systemClock;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cosntructors
|
||||
|
||||
public SayHelloWorldJob(SayHelloWorldJobConfiguration configuration,
|
||||
IRepository repository,
|
||||
ISystemClock systemClock)
|
||||
{
|
||||
_systemClock = systemClock;
|
||||
_repository = repository;
|
||||
_configuration = configuration;
|
||||
_stopWatch = new Stopwatch();
|
||||
}
|
||||
@@ -40,7 +35,6 @@ namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs
|
||||
{
|
||||
_stopWatch.Restart();
|
||||
Thread.Sleep(4000);
|
||||
var now = _systemClock.UtcNow;
|
||||
|
||||
_stopWatch.Stop();
|
||||
Debug.WriteLine($"---> Say hello to world from {_configuration.Name}, Duration: {_stopWatch.ElapsedMilliseconds / 1000}s");
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using GerstITS.Examples.Jobs.SayHelloWorld.Configurations;
|
||||
using GerstITS.Job;
|
||||
using Quartz;
|
||||
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs;
|
||||
|
||||
[DisallowConcurrentExecution]
|
||||
public class SayHelloWorldWithDefaultNameUsageJob : JobBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly SayHelloWorldWithDefaultNameUsageJobConfiguration _configuration;
|
||||
private readonly Stopwatch _stopWatch;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cosntructors
|
||||
|
||||
public SayHelloWorldWithDefaultNameUsageJob(SayHelloWorldWithDefaultNameUsageJobConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_stopWatch = new Stopwatch();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
_stopWatch.Restart();
|
||||
Thread.Sleep(4000);
|
||||
|
||||
_stopWatch.Stop();
|
||||
Debug.WriteLine($"---> Say hello to world from {_configuration.Name}, Duration: {_stopWatch.ElapsedMilliseconds / 1000}s");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user