conductor server端源码解析(3)-systemTask

1.system task的实现与管理:

所有的system task都继承自 com.netflix.conductor.core.execution.tasks.WorkflowSystemTask

在这里插入图片描述
所有的系统任务实现注册于 com.netflix.conductor.core.execution.tasks.SystemTaskRegistry
启动时,由spring将具体是systemTask实现注册到其中

在这里插入图片描述
系统任务分为同步执行任务,各类任务是同步还是异步执行是代码写死的,具体区分如下:
在这里插入图片描述
在这里插入图片描述

注:对于http task可进行全局配置

conductor.tasks.http.connectTimeout=
conductor.tasks.http.readTimeout=

2.异步系统任务的执行:

2.1 任务的拉取

conductor为每类 异步执行的SystemTask 创建一个线程,将待执行中的任务从队列中拉取出来:
com.netflix.conductor.core.execution.tasks.SystemTaskWorkerCoordinator#initSystemTaskExecutor
在这里插入图片描述
队列名即为taskType,例如HTTP类型的系统任务,其队列名为HTTP
在这里插入图片描述

通过定时任务从队列中拉取任务执行,默认的拉取间隔 pollInterval=50ms
com.netflix.conductor.core.execution.tasks.SystemTaskWorker#startPolling(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask, java.lang.String)
在这里插入图片描述其配置为:

//拉取系统任务的时间间隔,默认为50ms
conductor.app.systemTaskWorkerPollInterval=

2.2 任务的执行

具体的执行过程见 com.netflix.conductor.core.execution.tasks.SystemTaskWorker#pollAndExecute
在这里插入图片描述
拉取到的任务是提交到线程池中异步执行:
在这里插入图片描述
线程池的为简单的 固定线程数线程池,线程数量为conductor.app.systemTaskWorkerThreadCount配置的数量
在这里插入图片描述

具体的执行方法为:
com.netflix.conductor.core.execution.AsyncSystemTaskExecutor#execute
其中具体的任务执行为:com.netflix.conductor.core.execution.tasks.WorkflowSystemTask#start
在这里插入图片描述
该方法最后的finally块中进行下一个任务的驱动
在这里插入图片描述

2.3 任务的批量拉取配置:

每次拉取的任务数量由两个参数决定 SemaphoreUtil 和 com.netflix.conductor.core.execution.tasks.SystemTaskWorker#maxPollCount

其中 SemaphoreUtil 是所有systemTask任务统一的信号量控制器,防止一次拉取太多系统执行不过来,这里的threadCount是一个全局的

系统配置,设置用于执行systemTask是线程数,默认取值为: Runtime.getRuntime().availableProcessors() * 2 可通过配置修改

//com.netflix.conductor.core.config.ConductorProperties
 
//配置 systemTask是线程数
conductor.app.systemTaskWorkerThreadCount=

在这里插入图片描述
而maxPollCount 则是统一的拉取配置,默认为1

//com.netflix.conductor.core.config.ConductorProperties
 
//配置一次最多拉取的任务数量
conductor.app.systemTaskMaxPollCount=1

3.驱动任务流程:

与worker的执行流程相同,调用的方法为:
com.netflix.conductor.core.execution.DeciderService#decide(com.netflix.conductor.model.WorkflowModel)

1.若是新流程,则获取 待调度的任务信息:
com.netflix.conductor.core.execution.DeciderService#startWorkflow

2.对待调度任务判断超时时间、任务状态,获取当前流程中待调度任务、待更新任务:
com.netflix.conductor.core.execution.DeciderService#decide(com.netflix.conductor.model.WorkflowModel, java.util.List<com.netflix.conductor.model.TaskModel>)

3.调度任务,执行系统任务,将异步执行的系统任务和用户自定义任务push到队列中
com.netflix.conductor.core.execution.WorkflowExecutor#scheduleTask

异步系统任务入队列
com.netflix.conductor.core.execution.tasks.WorkflowSystemTask#start
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值