<p align="center">
<img src="http://www.justlive.vip/images/earth-frost.png" width="150" alt="" />
</p>
<h3 align="center">earth-frost</h3>
<p align="center">
earth-frost是一个轻量级分布式任务调度框架。
</p>
## 介绍
- 调度模块和执行模块分离
- 使用redis作为数据库
- 基于订阅模式实现服务注册和发现
- 演示地址: http://www.justlive.vip (请勿恶意攻击)
## 环境
- Angular: v1.x
- JDK: 1.8+
- Maven: 3+
- Redis: 2.8+
- Spring boot: 2.x
- Thymeleaf: 3
## 功能
1.0.0
- 简单易上手,支持web界面进行任务的CRUD
- 支持动态修改任务的开始,停止
- 调度中心支持集群部署,将任务的调度进行封装,支持分配各种不同的任务
- 执行器支持分布式,支持集群部署,可进行相应分组,在调度中心界面查看
- 支持伸缩扩展,调度中心和执行器都是基于redis订阅模式进行服务注册发现和任务调度,服务上下线发现及时
- 支持失败重试
- 任务监控和报警
- 动态编译任务,支持web界面编辑任务源码,创建任务
- 支持父子任务
- 运行报表
1.1.0
- 支持钉钉预警通知
- 调度记录增加执行时间
- 任务超时报警机制
- 支持分片任务
- 支持SimpleTrigger任务
- 支持非spring项目开发执行器
- misfire
1.2.0
- 修复分片父子任务执行多次问题
- 增加配置最大日志数
- 增加Spring项目执行案例
## 开发
frost-api
对外实体和接口
frost-core
定义调度、执行、注册发现等核心功能的接口和实现
frost-center
调度中心服务,包含安全认证和UI展示,依赖core实现调度逻辑
frost-executor
执行器服务,依赖core实现任务执行逻辑,包含开发脚本任务的部分实例以及配置样例
frost-client
客户端api,第三方项目可依赖client实现与调度中心交互
## 快速入门
### 启动Redis数据库
请下载并安装2.8+版本的Redis,单机或集群模式皆可。
调度中心和执行器均支持集群模式部署,集群模式下各节点需配置相同的Redis服务
### 导入源码
解压源码,按maven格式将源码导入IDE,源码结构如上述 [开发] 章节。
### 配置部署调度中心
#### 1.配置内容说明
```
# 登录账号
spring.boot.auth.enabled=true
spring.security.user.name=frost
spring.security.user.password=frost
# 报警通知发送邮件
spring.mail.host=smtp.mail.com
spring.mail.username=
spring.mail.password=
# 邮件通知
frost.notifier.mail.enabled=true
frost.notifier.mail.from=${spring.mail.username}
frost.notifier.mail.to=
frost.notifier.mail.subject=#{job.name} (#{job.id}) throws an exception
frost.notifier.mail.text=#{job.name} (#{job.id}) \n #{event.message}
# 钉钉通知
frost.notifier.dingtalk.enabled=false
frost.notifier.dingtalk.subject=There is something wrong with #{job.name} (#{job.id})
frost.notifier.dingtalk.text=#{job.name} (#{job.id}) \n #{event.message}
frost.notifier.dingtalk.accessToken=
frost.notifier.dingtalk.linkUrl=localhost:20000/center
# 系统配置
frost.system.corePoolSize=50
frost.system.maximumPoolSize=50
frost.system.keepAliveTime=300
frost.system.queueCapacity=200
# center处理worker数
frost.system.workers=10
# job并行处理个数
frost.system.parallel=2
# redis配置
# 0:单机模式, 1:集群模式,2:云托管模式,3:哨兵模式,4:主从模式
frost.redisson.mode=0
# 公共配置
frost.redisson.password=
frost.redisson.slaveConnectionPoolSize=50
frost.redisson.masterConnectionPoolSize=50
frost.redisson.timeout=3000
# 单机模式
frost.redisson.address=redis://localhost:6379
# 集群模式
frost.redisson.nodeAddresses=redis://localhost:6379,redis://localhost:6380,redis://localhost:6381
frost.redisson.scanInterval=2000
# 云托管模式
frost.redisson.nodeAddresses=redis://localhost:6379,redis://localhost:6380,redis://localhost:6381
frost.redisson.scanInterval=2000
frost.redisson.dnsMonitoringInterval=5000
# 哨兵模式
frost.redisson.sentinelAddresses=redis://localhost:6379,redis://localhost:6380,redis://localhost:6381
frost.redisson.scanInterval=2000
frost.redisson.masterName=mymaster
# 主从模式
frost.redisson.masterAddress=redis://127.0.0.1:6379
frost.redisson.slaveAddresses=redis://localhost:6380,redis://localhost:6381
frost.redisson.dnsMonitoringInterval=5000
```
#### 2.部署项目
正确进行上述配置,可将项目编译打包 mvn package(jar或war,相关打包操作参照Spring boot),调度中心访问地址:http://localhost:20000/center,访问可进入登录界面

登录成功后进入报表页面

#### 3.集群模式
支持集群模式部署,提供调度系统可用性。
集群模式需要注意:保持 登录账号保持一致,保持使用redis配置相同。建议使用Nginx为调度中心做负载均衡
### 配置部署执行器
提供的frost-executor项目可直接使用,也可集成到现有业务项目中使用
#### 1.依赖jar
在执行器项目中依赖如下jar包
```
<dependency>
<groupId>vip.justlive</groupId>
<artifactId>frost-core</artifactId>
</dependency>
```
#### 2.配置说明
```
# 系统配置
frost.system.corePoolSize=50
frost.system.maximumPoolSize=50
frost.system.keepAliveTime=300
frost.system.queueCapacity=200
# job并行处理个数
frost.system.parallel=2
# 执行器名称
frost.executor.name=${spring.application.name}
# 执行器Key
frost.executor.key=executor-demo
frost.executor.ip=
frost.executor.port=${server.port}
# 是否支持执行脚本任务
frost.executor.scriptJobEnabled=true
# 错过执行的阈值(毫秒)
frost.executor.misfireThreshold=5000
# 每个job最大日志保留数
frost.executor.maxLogSize=-1
# redis配置
# 0:单机模式, 1:集群模式,2:云托管模式,3:哨兵模式,4:主从模式
frost.redisson.mode=0
# 公共配置
frost.redisson.password=
frost.redisson.slaveConnectionPoolSize=50
frost.redisson.masterConnectionPoolSize=50
frost.redisson.timeout=3000
# 单机模式
frost.redisson.address=redis://localhost:6379
# 集群模式
frost.redisson.nodeAddresses=redis://localhost:6379,redis://localhost:6380,redis://localhost:6381
frost.redisson.scanInterval=2000
# 云托管模式
frost.redisson.nodeAddresses=redis://localhost:6379,redis://localhost:6380,redis://localhost:6381
frost.redisson.scanInterval=2000
frost.redisson.dnsMonitoringInterval=5000
# 哨兵模式
frost.redisson.sentinelAddresses=redis://localhost:6379,redis://localhost:6380,redis://localhost:6381
frost.redisson.scanInterval=2000
frost.redisson.masterName=mymaster
# 主从模式
frost.redisson.masterAddress=redis://127.0.0.1:6379
frost.redisson.slaveAddresses=redis://localhost:6380,redis://localhost:6381
frost.redisson.dnsMonitoringInterval=5000
```
#### 3.部署执行器
执行 `Container.initExecutor(...)` 进行初始化执行器,项目打包按照集成项目打包方式即可,部署后打开调度中心页面查看执行器页面。具体代码可参照`frost-executor`,包含Spring和非Spring项目启动方式

列表中出现部署的执行器则说明部署成功
### 开发一个简单的任务
该案例使用脚本任务模式,比使用实例模式只需要部署调度中心和执行器即可,脚本任务可在调度中心在线维护
#### 1.新增任务
登录调度中心,在任务管理界面点击新增任务,任务类型选择脚本模式,输入相应参数,点击保存。


#### 2.脚本模式开发
在任务管理列表的操作栏,点击刚新建任务的脚本按�