简介
说明
本文用示例介绍Power Job的用法。
PowerJob是一个定时任务中间件(框架),优点很多,PowerJob官网的对比图中可以看到PowerJob比Quartz、XXL-JOB等更加优秀。
个人认为XXL-JOB与PowerJob各有优缺点,它们的对比见:SpringBoot–定时任务–选型/对比/框架_IT利刃出鞘的博客-CSDN博客
官方
官网:http://www.powerjob.tech/
文档:https://www.yuque.com/powerjob/guidence/intro
快速开始:https://www.yuque.com/powerjob/guidence/nyio9g
github:https://github.com/PowerJob/PowerJob
相关网址
PowerJob的特性:PowerJob 简介 · 语雀
实战
下载项目
git clone https://github.com/PowerJob/PowerJob.git

启动服务端
1.创建数据库(仅需要创建数据库):
CREATE DATABASE IF NOT EXISTS `powerjob-daily` DEFAULT CHARSET utf8mb4
2.修改配置文件

配置文件的说明:官方文档写的非常详细,此处不再赘述。
需要修改的地方为数据库配置:
- spring.datasource.core.jdbc-url
- spring.datasource.core.username
- spring.datasource.core.password
(当然,有 mongoDB 的同学也可以修改spring.data.mongodb.uri以获取完全版体验。)
本处我的配置为:
此内容仅限VIP查看,请先登录
运行结果


可以看到,只会有一台机器在执行。我用的是单机处理器,它会选择一台最健康的机器进行执行。
执行记录



问题及解决
问题:我设置的是CRON,每5秒执行,但它实际15秒执行一次。
原因:Powerjob的CRON模式下,时间轮是15秒扫描一次,这时间间隔不能小于15秒。若低于15秒会按15秒运行。
解决方案:改为固定频率或固定延迟进行。
修改设置如下:

执行结果:

请先
!