diff --git a/src/Foundatio.Extensions.Hosting/Jobs/JobOptionsBuilder.cs b/src/Foundatio.Extensions.Hosting/Jobs/JobOptionsBuilder.cs index 731b0584..708a5162 100644 --- a/src/Foundatio.Extensions.Hosting/Jobs/JobOptionsBuilder.cs +++ b/src/Foundatio.Extensions.Hosting/Jobs/JobOptionsBuilder.cs @@ -42,7 +42,7 @@ public HostedJobOptionsBuilder JobFactory(Func value) return this; } - public HostedJobOptionsBuilder RunContinuous(bool value) + public HostedJobOptionsBuilder RunContinuous(bool value = true) { Target.RunContinuous = value; return this; @@ -72,7 +72,7 @@ public HostedJobOptionsBuilder InstanceCount(int value) return this; } - public HostedJobOptionsBuilder WaitForStartupActions(bool value) + public HostedJobOptionsBuilder WaitForStartupActions(bool value = true) { Target.WaitForStartupActions = value; return this; diff --git a/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobOptionsBuilder.cs b/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobOptionsBuilder.cs index 37526e5a..bf2b6802 100644 --- a/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobOptionsBuilder.cs +++ b/src/Foundatio.Extensions.Hosting/Jobs/ScheduledJobOptionsBuilder.cs @@ -36,13 +36,13 @@ public ScheduledJobOptionsBuilder JobFactory(Func value) return this; } - public ScheduledJobOptionsBuilder WaitForStartupActions(bool value) + public ScheduledJobOptionsBuilder WaitForStartupActions(bool value = true) { Target.WaitForStartupActions = value; return this; } - public ScheduledJobOptionsBuilder Distributed(bool value) + public ScheduledJobOptionsBuilder Distributed(bool value = true) { Target.IsDistributed = value; return this; diff --git a/src/Foundatio/Jobs/JobBase.cs b/src/Foundatio/Jobs/JobBase.cs index a19a0b59..8c2aa3c6 100644 --- a/src/Foundatio/Jobs/JobBase.cs +++ b/src/Foundatio/Jobs/JobBase.cs @@ -9,7 +9,7 @@ namespace Foundatio.Jobs; public abstract class JobBase : IJob, IHaveLogger, IHaveTimeProvider { - private readonly TimeProvider _timeProvider; + protected readonly TimeProvider _timeProvider; protected readonly ILogger _logger; public JobBase(ILoggerFactory loggerFactory = null) : this(null, loggerFactory) diff --git a/src/Foundatio/Jobs/JobWithLockBase.cs b/src/Foundatio/Jobs/JobWithLockBase.cs index d81317e9..8ca1e626 100644 --- a/src/Foundatio/Jobs/JobWithLockBase.cs +++ b/src/Foundatio/Jobs/JobWithLockBase.cs @@ -8,17 +8,25 @@ namespace Foundatio.Jobs; -public abstract class JobWithLockBase : IJob, IHaveLogger +public abstract class JobWithLockBase : IJob, IHaveLogger, IHaveTimeProvider { protected readonly ILogger _logger; + private readonly TimeProvider _timeProvider; public JobWithLockBase(ILoggerFactory loggerFactory = null) { _logger = loggerFactory?.CreateLogger(GetType()) ?? NullLogger.Instance; } + public JobWithLockBase(TimeProvider timeProvider, ILoggerFactory loggerFactory = null) + { + _timeProvider = timeProvider ?? TimeProvider.System; + _logger = loggerFactory?.CreateLogger(GetType()) ?? NullLogger.Instance; + } + public string JobId { get; } = Guid.NewGuid().ToString("N").Substring(0, 10); ILogger IHaveLogger.Logger => _logger; + TimeProvider IHaveTimeProvider.TimeProvider => _timeProvider; public virtual async Task RunAsync(CancellationToken cancellationToken = default) {