mirror of https://github.com/abpframework/abp.git
committed by
GitHub
17 changed files with 317 additions and 75 deletions
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Quartz; |
||||
|
|
||||
|
namespace Volo.Abp.BackgroundJobs.Quartz |
||||
|
{ |
||||
|
public class AbpBackgroundJobQuartzOptions |
||||
|
{ |
||||
|
public int RetryCount { get; set; } |
||||
|
|
||||
|
public int RetryIntervalMillisecond { get; set; } |
||||
|
|
||||
|
|
||||
|
[NotNull] |
||||
|
public Func<int, IJobExecutionContext, JobExecutionException,Task> RetryStrategy |
||||
|
{ |
||||
|
get => _retryStrategy; |
||||
|
set => _retryStrategy = Check.NotNull(value, nameof(value)); |
||||
|
} |
||||
|
private Func<int, IJobExecutionContext, JobExecutionException,Task> _retryStrategy; |
||||
|
|
||||
|
public AbpBackgroundJobQuartzOptions() |
||||
|
{ |
||||
|
RetryCount = 3; |
||||
|
RetryIntervalMillisecond = 3000; |
||||
|
_retryStrategy = DefaultRetryStrategy; |
||||
|
} |
||||
|
|
||||
|
private async Task DefaultRetryStrategy(int retryIndex, IJobExecutionContext executionContext, JobExecutionException exception) |
||||
|
{ |
||||
|
exception.RefireImmediately = true; |
||||
|
|
||||
|
var retryCount = executionContext.JobDetail.JobDataMap.GetIntValue(QuartzBackgroundJobManager.JobDataPrefix+ nameof(RetryCount)); |
||||
|
if (retryIndex > retryCount) |
||||
|
{ |
||||
|
exception.RefireImmediately = false; |
||||
|
exception.UnscheduleAllTriggers = true; |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
var retryInterval = executionContext.JobDetail.JobDataMap.GetIntValue(QuartzBackgroundJobManager.JobDataPrefix+ nameof(RetryIntervalMillisecond)); |
||||
|
await Task.Delay(retryInterval); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Quartz; |
||||
|
|
||||
|
namespace Volo.Abp.BackgroundJobs.Quartz |
||||
|
{ |
||||
|
public static class QuartzBackgroundJobManageExtensions |
||||
|
{ |
||||
|
public static async Task<string> EnqueueAsync<TArgs>(this IBackgroundJobManager backgroundJobManager, |
||||
|
TArgs args, int retryCount, int retryIntervalMillisecond, |
||||
|
BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) |
||||
|
{ |
||||
|
if (backgroundJobManager is QuartzBackgroundJobManager quartzBackgroundJobManager) |
||||
|
{ |
||||
|
return await quartzBackgroundJobManager.ReEnqueueAsync(args, retryCount, retryIntervalMillisecond, |
||||
|
priority, delay); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
namespace Volo.Abp.BackgroundWorkers.Quartz |
||||
|
{ |
||||
|
public class AbpBackgroundWorkerQuartzOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Default : true.
|
||||
|
/// </summary>
|
||||
|
public bool IsAutoRegisterEnabled { get; set; } = true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Specialized; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Quartz; |
||||
|
|
||||
|
namespace Volo.Abp.Quartz |
||||
|
{ |
||||
|
public class AbpQuartzOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The quartz configuration. Available properties can be found within Quartz.Impl.StdSchedulerFactory.
|
||||
|
/// </summary>
|
||||
|
public NameValueCollection Properties { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// How long Quartz should wait before starting. Default: 0.
|
||||
|
/// </summary>
|
||||
|
public TimeSpan StartDelay { get; set; } |
||||
|
|
||||
|
[NotNull] |
||||
|
public Func<IScheduler, Task> StartSchedulerFactory |
||||
|
{ |
||||
|
get => _startSchedulerFactory; |
||||
|
set => _startSchedulerFactory = Check.NotNull(value, nameof(value)); |
||||
|
} |
||||
|
private Func<IScheduler, Task> _startSchedulerFactory; |
||||
|
|
||||
|
public AbpQuartzOptions() |
||||
|
{ |
||||
|
Properties = new NameValueCollection(); |
||||
|
StartDelay = new TimeSpan(0); |
||||
|
_startSchedulerFactory = StartSchedulerAsync; |
||||
|
} |
||||
|
|
||||
|
private async Task StartSchedulerAsync(IScheduler scheduler) |
||||
|
{ |
||||
|
if (StartDelay.Ticks > 0) |
||||
|
{ |
||||
|
await scheduler.StartDelayed(StartDelay); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
await scheduler.Start(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,23 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Specialized; |
|
||||
|
|
||||
namespace Volo.Abp.Quartz |
|
||||
{ |
|
||||
public class AbpQuartzPreOptions |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// The quartz configuration. Available properties can be found within Quartz.Impl.StdSchedulerFactory.
|
|
||||
/// </summary>
|
|
||||
public NameValueCollection Properties { get; set; } |
|
||||
/// <summary>
|
|
||||
/// How long Quartz should wait before starting. Default: 0.
|
|
||||
/// </summary>
|
|
||||
public TimeSpan StartDelay { get; set; } |
|
||||
|
|
||||
public AbpQuartzPreOptions() |
|
||||
{ |
|
||||
Properties = new NameValueCollection(); |
|
||||
StartDelay = new TimeSpan(0); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue