Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple job ergonomic improvements #307

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Foundatio.Extensions.Hosting/Jobs/JobOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public HostedJobOptionsBuilder JobFactory(Func<IServiceProvider, IJob> value)
return this;
}

public HostedJobOptionsBuilder RunContinuous(bool value)
public HostedJobOptionsBuilder RunContinuous(bool value = true)
{
Target.RunContinuous = value;
return this;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public ScheduledJobOptionsBuilder JobFactory(Func<IServiceProvider, IJob> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio/Jobs/JobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/Foundatio/Jobs/JobWithLockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JobResult> RunAsync(CancellationToken cancellationToken = default)
{
Expand Down