Browse Source

feat(tasks): if the task fails, recalculate the priority

pull/457/head
cKey 4 years ago
parent
commit
44220eb2cc
  1. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobInfo.cs
  2. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/README.md
  3. 0
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/IJobRunnableExecuter.cs
  4. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs
  5. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/README.md

2
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobInfo.cs

@ -62,7 +62,7 @@ public class JobInfo
/// </summary>
public JobType JobType { get; set; } = JobType.Once;
/// <summary>
/// Cron表达式,如果是持续任务需要指定
/// Cron表达式,如果是周期性任务需要指定
/// </summary>
public string Cron { get; set; }
/// <summary>

2
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/README.md

@ -1,6 +1,6 @@
# LINGYUN.Abp.BackgroundTasks.Quartz
后台任务(队列)模块的Quartz实现, 使用任务适配器来做到任务的幂等性控制.
后台任务(队列)模块的Quartz实现.
并添加一个监听器用于通知管理者任务状态
## 配置使用

0
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobRunnableExecuter.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/IJobRunnableExecuter.cs

14
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs

@ -28,9 +28,21 @@ internal class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDepe
if (context.EventData.Exception != null)
{
job.TryCount += 1;
// 将任务标记为运行中, 会被轮询重新进入队列
job.Status = JobStatus.Running;
job.Result = context.EventData.Exception.Message;
// 多次异常后需要重新计算优先级
if (job.TryCount <= (job.MaxTryCount / 2) &&
job.TryCount > (job.MaxTryCount / 3))
{
job.Priority = JobPriority.BelowNormal;
}
else if (job.TryCount > (job.MaxTryCount / 1.5))
{
job.Priority = JobPriority.Low;
}
if (job.TryCount > job.MaxTryCount)
{
job.Status = JobStatus.Stopped;

2
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/README.md

@ -50,6 +50,8 @@ public class DemoClass
Cron = "0/5 * * * * ? ",
TryCount = 10,
Status = JobStatus.Running,
// 定义此字段处理并发
LockTimeOut = 120,
});
// 将一次性任务添加到队列, 将在10(Interval)秒后被执行

Loading…
Cancel
Save