Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
85b8fa40
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
707
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
85b8fa40
编写于
8月 17, 2022
作者:
薛 之 谦
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/ws-3.0.0' into ws-3.0.0
上级
13fc6601
e9e6ea70
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
11 deletion
+37
-11
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/async/AsyncTaskExecutionContext.java
...uler/plugin/task/api/async/AsyncTaskExecutionContext.java
+25
-6
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/AsyncTaskDelayQueue.java
...inscheduler/server/worker/runner/AsyncTaskDelayQueue.java
+7
-2
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/AsyncTaskLooper.java
...olphinscheduler/server/worker/runner/AsyncTaskLooper.java
+4
-2
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/AsyncWorkerDelayTaskExecuteRunnable.java
...er/worker/runner/AsyncWorkerDelayTaskExecuteRunnable.java
+1
-1
未找到文件。
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/async/AsyncTaskExecutionContext.java
浏览文件 @
85b8fa40
...
...
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.plugin.task.api.async;
import
lombok.Data
;
import
lombok.NonNull
;
import
org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext
;
import
java.util.concurrent.Delayed
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -26,25 +27,43 @@ import java.util.concurrent.TimeUnit;
@Data
public
class
AsyncTaskExecutionContext
implements
Delayed
{
private
final
int
taskInstanceId
;
private
final
TaskExecutionContext
taskExecutionContext
;
private
final
@NonNull
AsyncTaskExecuteFunction
asyncTaskExecuteFunction
;
private
final
AsyncTaskExecuteFunction
asyncTaskExecuteFunction
;
private
final
@NonNull
AsyncTaskCallbackFunction
asyncTaskCallbackFunction
;
private
final
AsyncTaskCallbackFunction
asyncTaskCallbackFunction
;
public
AsyncTaskExecutionContext
(
int
taskInstanceId
,
private
long
currentStartTime
;
private
int
executeTimes
;
private
final
long
executeInterval
;
public
AsyncTaskExecutionContext
(
@NonNull
TaskExecutionContext
taskExecutionContext
,
@NonNull
AsyncTaskExecuteFunction
asyncTaskExecuteFunction
,
@NonNull
AsyncTaskCallbackFunction
asyncTaskCallbackFunction
)
{
this
.
task
InstanceId
=
taskInstanceId
;
this
.
task
ExecutionContext
=
taskExecutionContext
;
this
.
asyncTaskExecuteFunction
=
asyncTaskExecuteFunction
;
this
.
asyncTaskCallbackFunction
=
asyncTaskCallbackFunction
;
this
.
currentStartTime
=
System
.
currentTimeMillis
();
this
.
executeTimes
=
0
;
this
.
executeInterval
=
Math
.
max
(
asyncTaskExecuteFunction
.
getTaskExecuteInterval
().
toMillis
(),
1000L
);
}
public
void
refreshStartTime
()
{
currentStartTime
=
System
.
currentTimeMillis
();
}
@Override
public
long
getDelay
(
TimeUnit
unit
)
{
return
unit
.
toSeconds
(
asyncTaskExecuteFunction
.
getTaskExecuteInterval
().
toMillis
());
// The first time doesn't have delay
if
(
executeTimes
==
0
)
{
executeTimes
++;
return
0
;
}
return
unit
.
convert
(
currentStartTime
+
executeInterval
-
System
.
currentTimeMillis
(),
TimeUnit
.
MILLISECONDS
);
}
@Override
public
int
compareTo
(
Delayed
o
)
{
if
(
o
==
null
)
{
...
...
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/AsyncTaskDelayQueue.java
浏览文件 @
85b8fa40
...
...
@@ -19,11 +19,15 @@ package org.apache.dolphinscheduler.server.worker.runner;
import
lombok.NonNull
;
import
lombok.experimental.UtilityClass
;
import
org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext
;
import
org.apache.dolphinscheduler.plugin.task.api.async.AsyncTaskCallbackFunction
;
import
org.apache.dolphinscheduler.plugin.task.api.async.AsyncTaskExecuteFunction
;
import
org.apache.dolphinscheduler.plugin.task.api.async.AsyncTaskExecutionContext
;
import
org.apache.dolphinscheduler.plugin.task.api.async.AsyncTaskExecutionStatus
;
import
javax.annotation.Nullable
;
import
java.time.Duration
;
import
java.util.concurrent.DelayQueue
;
import
java.util.concurrent.TimeUnit
;
@UtilityClass
public
class
AsyncTaskDelayQueue
{
...
...
@@ -31,11 +35,12 @@ public class AsyncTaskDelayQueue {
private
final
DelayQueue
<
AsyncTaskExecutionContext
>
asyncTaskCheckDelayQueue
=
new
DelayQueue
<>();
public
void
addAsyncTask
(
@NonNull
AsyncTaskExecutionContext
asyncTaskExecutionContext
)
{
asyncTaskExecutionContext
.
refreshStartTime
();
asyncTaskCheckDelayQueue
.
add
(
asyncTaskExecutionContext
);
}
public
@Nullable
AsyncTaskExecutionContext
pollAsyncTask
()
throws
InterruptedException
{
return
asyncTaskCheckDelayQueue
.
poll
(
1
,
TimeUnit
.
MINUTES
);
return
asyncTaskCheckDelayQueue
.
take
(
);
}
}
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/AsyncTaskLooper.java
浏览文件 @
85b8fa40
...
...
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.server.worker.runner;
import
org.apache.dolphinscheduler.common.thread.BaseDaemonThread
;
import
org.apache.dolphinscheduler.common.thread.Stopper
;
import
org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext
;
import
org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager
;
import
org.apache.dolphinscheduler.plugin.task.api.async.AsyncTaskCallbackFunction
;
import
org.apache.dolphinscheduler.plugin.task.api.async.AsyncTaskExecuteFunction
;
...
...
@@ -61,12 +62,13 @@ public class AsyncTaskLooper extends BaseDaemonThread {
if
(
asyncTaskExecutionContext
==
null
)
{
continue
;
}
if
(
TaskExecutionContextCacheManager
.
getByTaskInstanceId
(
asyncT
askExecutionContext
.
getTaskInstanceId
())
==
null
)
{
final
TaskExecutionContext
taskExecutionContext
=
asyncTaskExecutionContext
.
getTaskExecutionContext
();
if
(
TaskExecutionContextCacheManager
.
getByTaskInstanceId
(
t
askExecutionContext
.
getTaskInstanceId
())
==
null
)
{
logger
.
warn
(
"Cannot find the taskInstance from TaskExecutionContextCacheManager, the task may already been killed"
);
continue
;
}
asyncCheckThreadPool
.
submit
(()
->
{
Thread
.
currentThread
().
setName
(
taskExecutionContext
.
getTaskLogName
());
final
AsyncTaskExecuteFunction
asyncTaskExecuteFunction
=
asyncTaskExecutionContext
.
getAsyncTaskExecuteFunction
();
final
AsyncTaskCallbackFunction
asyncTaskCallbackFunction
=
asyncTaskExecutionContext
.
getAsyncTaskCallbackFunction
();
try
{
...
...
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/AsyncWorkerDelayTaskExecuteRunnable.java
浏览文件 @
85b8fa40
...
...
@@ -55,7 +55,7 @@ public class AsyncWorkerDelayTaskExecuteRunnable extends WorkerDelayTaskExecuteR
task
.
handle
();
// submit the task to async task queue
asyncTaskExecutionContext
=
new
AsyncTaskExecutionContext
(
taskExecutionContext
.
getTaskInstanceId
()
,
taskExecutionContext
,
task
.
getAsyncTaskExecuteFunction
(),
new
AsyncTaskCallbackFunctionImpl
(
this
)
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录