Introduce BackgroundJobWorkerOptions

pull/395/head
Halil ibrahim Kalkan 7 years ago
parent 761fa1d59a
commit d963f7cd48

@ -7,51 +7,14 @@ namespace Volo.Abp.BackgroundJobs
{
public Dictionary<string, Type> JobTypes { get; }
//TODO: Move options related to default backgroundjob manager to another class
/// <summary>
/// Default: true.
/// </summary>
public bool IsJobExecutionEnabled { get; set; } = true;
/// <summary>
/// Interval between polling jobs from <see cref="IBackgroundJobStore"/>.
/// Default value: 5000 (5 seconds).
/// </summary>
public int JobPollPeriod { get; set; }
/// <summary>
/// Maximum count of jobs to fetch from data store in one loop.
/// </summary>
public int MaxJobFetchCount { get; set; } = 1000;
/// <summary>
/// Default duration (as seconds) for the first wait on a failure.
/// Default value: 60 (1 minutes).
/// </summary>
public int DefaultFirstWaitDuration { get; set; }
/// <summary>
/// Default timeout value (as seconds) for a job before it's abandoned (<see cref="BackgroundJobInfo.IsAbandoned"/>).
/// Default value: 172,800 (2 days).
/// </summary>
public int DefaultTimeout { get; set; }
/// <summary>
/// Default wait factor for execution failures.
/// This amount is multiplated by last wait time to calculate next wait time.
/// Default value: 2.0.
/// </summary>
public double DefaultWaitFactor { get; set; }
public bool IsEnabled { get; set; } = true;
public BackgroundJobOptions()
{
JobTypes = new Dictionary<string, Type>();
JobPollPeriod = 5000;
DefaultFirstWaitDuration = 60;
DefaultTimeout = 172800;
DefaultWaitFactor = 2.0;
}
internal Type GetJobType(string jobName)

@ -31,7 +31,7 @@ namespace Volo.Abp.BackgroundJobs
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<BackgroundJobOptions>>().Value;
if (options.IsJobExecutionEnabled)
if (options.IsEnabled)
{
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()

@ -12,7 +12,7 @@ namespace Volo.Abp.BackgroundJobs
{
protected IBackgroundJobExecuter JobExecuter { get; }
protected IBackgroundJobStore Store { get; }
protected BackgroundJobOptions Options { get; }
protected BackgroundJobWorkerOptions Options { get; }
protected IClock Clock { get; }
/// <summary>
@ -22,7 +22,7 @@ namespace Volo.Abp.BackgroundJobs
IBackgroundJobStore store,
AbpTimer timer,
IBackgroundJobExecuter jobExecuter,
IOptions<BackgroundJobOptions> options,
IOptions<BackgroundJobWorkerOptions> options,
IClock clock)
: base(timer)
{

@ -0,0 +1,45 @@
namespace Volo.Abp.BackgroundJobs
{
public class BackgroundJobWorkerOptions
{
/// <summary>
/// Interval between polling jobs from <see cref="IBackgroundJobStore"/>.
/// Default value: 5000 (5 seconds).
/// </summary>
public int JobPollPeriod { get; set; }
/// <summary>
/// Maximum count of jobs to fetch from data store in one loop.
/// Default: 1000.
/// </summary>
public int MaxJobFetchCount { get; set; }
/// <summary>
/// Default duration (as seconds) for the first wait on a failure.
/// Default value: 60 (1 minutes).
/// </summary>
public int DefaultFirstWaitDuration { get; set; }
/// <summary>
/// Default timeout value (as seconds) for a job before it's abandoned (<see cref="BackgroundJobInfo.IsAbandoned"/>).
/// Default value: 172,800 (2 days).
/// </summary>
public int DefaultTimeout { get; set; }
/// <summary>
/// Default wait factor for execution failures.
/// This amount is multiplated by last wait time to calculate next wait time.
/// Default value: 2.0.
/// </summary>
public double DefaultWaitFactor { get; set; }
public BackgroundJobWorkerOptions()
{
MaxJobFetchCount = 1000;
JobPollPeriod = 5000;
DefaultFirstWaitDuration = 60;
DefaultTimeout = 172800;
DefaultWaitFactor = 2.0;
}
}
}

@ -36,7 +36,7 @@ namespace Volo.Abp.BackgroundJobs.DemoApp
});
});
context.Services.Configure<BackgroundJobOptions>(options =>
context.Services.Configure<BackgroundJobWorkerOptions>(options =>
{
//Configure for fast running
options.JobPollPeriod = 1000;

@ -15,7 +15,7 @@ namespace Volo.Abp.BackgroundJobs
{
context.Services.Configure<BackgroundJobOptions>(options =>
{
options.IsJobExecutionEnabled = false;
options.IsEnabled = false;
});
context.Services.AddAssemblyOf<BackgroundJobsTestBaseModule>();

Loading…
Cancel
Save