using System.Diagnostics; using System.Threading; using GerstITS.Data; using GerstITS.Examples.Jobs.SayHelloWorld.Configurations; using GerstITS.Job; using GerstITS.System.Environment; using Quartz; namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs { [DisallowConcurrentExecution] public class SayHelloWorldJob : JobBase { #region Fields 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(); } #endregion #region Methods protected override void Execute() { _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"); } #endregion } }