diff --git a/GerstITS.Examples.Api/appsettings.json b/GerstITS.Examples.Api/appsettings.json index ec5d541..b51db38 100644 --- a/GerstITS.Examples.Api/appsettings.json +++ b/GerstITS.Examples.Api/appsettings.json @@ -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" ], diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/Configurations/SayHelloWorldWithDefaultNameUsageJobConfiguration.cs b/GerstITS.Examples.Jobs.SayHelloWorld/Configurations/SayHelloWorldWithDefaultNameUsageJobConfiguration.cs new file mode 100644 index 0000000..1bb9700 --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/Configurations/SayHelloWorldWithDefaultNameUsageJobConfiguration.cs @@ -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($"{prefix}:{nameof(Name)}"); + } + + #endregion +} \ No newline at end of file diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs b/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs index c0cf976..18e53f5 100644 --- a/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs +++ b/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs @@ -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"); diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldWithDefaultNameUsageJob.cs b/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldWithDefaultNameUsageJob.cs new file mode 100644 index 0000000..324b242 --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldWithDefaultNameUsageJob.cs @@ -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 +} \ No newline at end of file