mirror of https://github.com/abpframework/abp.git
4 changed files with 121 additions and 12 deletions
@ -0,0 +1,48 @@ |
|||
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; } |
|||
|
|||
|
|||
public const string RetryIndex = "RetryIndex"; |
|||
|
|||
[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(nameof(RetryCount)); |
|||
if (retryIndex > retryCount) |
|||
{ |
|||
exception.RefireImmediately = false; |
|||
exception.UnscheduleAllTriggers = true; |
|||
return; |
|||
} |
|||
|
|||
var retryInterval = executionContext.JobDetail.JobDataMap.GetIntValue(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; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue