From 279916ae079f736d6e5b339464fcca1cb70b9ea9 Mon Sep 17 00:00:00 2001 From: Xuanye Wong Date: Mon, 26 Apr 2021 14:52:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=98=BB=E5=A1=9E=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=AD=96=E7=95=A5=E8=AE=BE=E7=BD=AE=E4=B8=BA=E2=80=9C?= =?UTF-8?q?=E4=B8=A2=E5=BC=83=E5=90=8E=E7=BB=AD=E8=B0=83=E5=BA=A6=E2=80=9C?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=9C=89=E7=AC=AC=E4=B8=80=E6=AC=A1=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E6=AD=A3=E5=B8=B8=E6=89=A7=E8=A1=8C=EF=BC=8C=E5=90=8E?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E6=89=80=E6=9C=89=E8=B0=83=E5=BA=A6=E9=83=BD?= =?UTF-8?q?=E8=A2=AB=E4=B8=A2=E5=BC=83=E4=BA=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/releasenotes.props | 1 + build/version.props | 2 +- samples/ASPNetCoreExecutor/DemoJobHandler.cs | 11 +++++++---- src/DotXxlJob.Core/JobDispatcher.cs | 9 +++++++-- src/DotXxlJob.Core/Queue/JobTaskQueue.cs | 7 +++++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/build/releasenotes.props b/build/releasenotes.props index b36895d..b3aadb2 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -3,6 +3,7 @@ 1. 修改异步方式读取RequestBody 2. 兼容xxl-jobv2.3版本回调函数参数变更的问题 + 3. 修复阻塞处理策略设置为“丢弃后续调度“,只有第一次调度正常执行,后面的所有调度都被丢弃了的问题 diff --git a/build/version.props b/build/version.props index c8130d7..751defc 100644 --- a/build/version.props +++ b/build/version.props @@ -1,5 +1,5 @@ - 2.3.0 + 2.3.1 diff --git a/samples/ASPNetCoreExecutor/DemoJobHandler.cs b/samples/ASPNetCoreExecutor/DemoJobHandler.cs index 70d65a7..1e894a7 100644 --- a/samples/ASPNetCoreExecutor/DemoJobHandler.cs +++ b/samples/ASPNetCoreExecutor/DemoJobHandler.cs @@ -10,11 +10,14 @@ namespace ASPNetCoreExecutor [JobHandler("demoJobHandler")] public class DemoJobHandler:AbstractJobHandler { - public override Task Execute(JobExecuteContext context) - { + public override async Task Execute(JobExecuteContext context) + { context.JobLogger.Log("receive demo job handler,parameter:{0}",context.JobParameter); - - return Task.FromResult(ReturnT.SUCCESS); + context.JobLogger.Log("开始休眠120秒"); + // + await Task.Delay(10 * 1000); + context.JobLogger.Log("休眠120秒结束"); + return ReturnT.SUCCESS; } } } \ No newline at end of file diff --git a/src/DotXxlJob.Core/JobDispatcher.cs b/src/DotXxlJob.Core/JobDispatcher.cs index 00e19bf..35f835d 100644 --- a/src/DotXxlJob.Core/JobDispatcher.cs +++ b/src/DotXxlJob.Core/JobDispatcher.cs @@ -82,7 +82,12 @@ namespace DotXxlJob.Core //丢弃后续的 if (Constants.ExecutorBlockStrategy.DISCARD_LATER == triggerParam.ExecutorBlockStrategy) { - return ReturnT.Failed($"block strategy effect:{triggerParam.ExecutorBlockStrategy}"); + //存在还没执行完成的任务 + if (taskQueue.IsRunning()) + { + return ReturnT.Failed($"block strategy effect:{triggerParam.ExecutorBlockStrategy}"); + } + //否则还是继续做 } //覆盖较早的 if (Constants.ExecutorBlockStrategy.COVER_EARLY == triggerParam.ExecutorBlockStrategy) @@ -109,7 +114,7 @@ namespace DotXxlJob.Core } private void TriggerCallback(object sender, HandleCallbackParam callbackParam) - { + { this._callbackTaskQueue.Push(callbackParam); } diff --git a/src/DotXxlJob.Core/Queue/JobTaskQueue.cs b/src/DotXxlJob.Core/Queue/JobTaskQueue.cs index 6b10135..dfa3d22 100644 --- a/src/DotXxlJob.Core/Queue/JobTaskQueue.cs +++ b/src/DotXxlJob.Core/Queue/JobTaskQueue.cs @@ -27,8 +27,15 @@ namespace DotXxlJob.Core public event EventHandler CallBack; + + + public bool IsRunning() + { + return _cancellationTokenSource !=null; + } + /// /// 覆盖之前的队列