Giter VIP home page Giter VIP logo

ant-task's Introduction

ant-task

一个轻量级的定时任务管理器

简介

Spring Boot中有一个自带的**@Scheduled**注解,可以用于启动定时任务,使用很方便, 但也存在着不足,例如定时任务直接写死、方法无参数、不能随时启停等等。 ant-task就是为了解决这些问题而存在的,在解决问题的同时也一如既往的方便接入,ant-task特性如下:

  • 图形化界面管理
  • 方便快捷接入
  • 支持随时启停任务
  • 支持动态参数传递
  • 支持动态修改任务时间
  • 支持Cron表达式
  • 支持日志ID跟踪

注意:因为没有使用第三方存储,所以不适合分布式项目,下个版本更新

安装

maven

<dependency>
  <groupId>com.github.hwywl</groupId>
  <artifactId>ant-task</artifactId>
  <version>1.0.4-RELEASE</version>
</dependency>

Gradle

implementation 'com.github.hwywl:ant-task:1.0.4-RELEASE'

使用

使用很简单,只要两步即可接入(本项目依赖Spring Boot中的spring-boot-starter-web组件)。

  1. 在pom.xml中引入上面的依赖。
  2. 在Spring Boot配置文件中设置如下配置,根据不同的配置文件二选一即可。
# application.yml

ant-task:
  conf:
    pool-size: 10
    file-path: /home/ec2-user/server/sms/task.properties
# application.properties

# 定时任务线程池,默认为 6
ant-task.conf.pool-size=10
# 任务数据配置存储路径(必填)
ant-task.conf.file-path=/home/ec2-user/server/sms/task.properties

此时就已经成功接入了,是不是很简单,我们启动项目访问:http://localhost:{port}/task.html 进入页面。

看到页面说明我们接入成功了,接下来我们配置一个数据试一下。

新建一个测试类:

/**
 * 测试定时任务
 * @author HWY
 * 2022年12月13日15:07:44
 */
@Component("schedulingTask")
public class TaskDemo {
    public void taskParams(String params) {
        System.out.println("定时执行有参任务:" + params);
    }

    public void taskJsonParams(TaskBean params) {
        System.out.println("定时执行有参任务:" + params);
    }

    public void taskNoParams() {
        System.out.println("定时执行无参任务!");
    }

    class TaskBean{
        /**
         * id
         */
        private Integer id;

        /**
         * 账户id
         */
        private String customerId;
    }
}

写好测试类之后我们重启项目,进入上面URL那个配置界面,进行如下配置:

或者试用JSON参数配置

配置非常简单,点击确定定时任务就开始执行了,我配置了两台测试,一个有参一个无参,来看看效果。

运行结果如下:

技术栈

  • SpringBoot
  • ThreadPoolTaskScheduler 线程池
  • Vue

版本迭代

1.0.4-RELEASE

  • 小版本更新各个包版本

1.0.3-RELEASE

  • 增加参数对JSON数据的支持,可以让入参的Bean对象直接接收
  • 修复因更新导致的任务重复执行问题

1.0.2-RELEASE

  • 增加页面的方便配置
  • 增加任务状态开关
  • 发布到**仓库

1.0.1-RELEASE

  • 实现基础定时功能
  • 实现手动文件可配置化

感谢

  • 感谢江南一点雨提供了思路
  • 工具还有不足之处,请大家Issues ヾ(๑╹◡╹)ノ"
  • 我那么可爱你不点个star吗 φ(>ω<*)

问题建议

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.