netstao / gopherCron

golang 开箱即用的秒级分布式定时任务系统

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

firetower logo

Downloads Build Status Package Utilities Version license

GopherCron

开箱即用的分布式可视化crontab

可以通过配置文件指定某个节点所受理的业务线,从而做到业务统一管理但隔离调度

依赖

  • Etcd # 服务注册与发现
  • Gin # webapi 提供可视化操作
  • MongoDB # 任务日志存储
  • cronexpr # github.com/gorhill/cronexpr cron表达式解析器

实现功能

  • 秒级定时任务
  • 任务日志查看
  • 随时结束任务进程
  • 分布式扩展
  • 健康节点检测 (分项目显示对应的健康节点IP及节点数)

cronexpr 秒级cron表达式介绍(引用)

* * * * * * * 
Field name     Mandatory?   Allowed values    Allowed special characters
----------     ----------   --------------    --------------------------
Seconds        No           0-59              * / , -
Minutes        Yes          0-59              * / , -
Hours          Yes          0-23              * / , -
Day of month   Yes          1-31              * / , - L W
Month          Yes          1-12 or JAN-DEC   * / , -
Day of week    Yes          0-6 or SUN-SAT    * / , - L #
Year           No           1970–2099         * / , -

使用方法

下载项目到本地并编译,根据cmd文件夹下service和client中包含的conf/config-default.toml进行配置

service 配置文件

log_level = "debug"

[deploy]
# 当前的环境:dev、release
environment = "release"
# 对外提供的端口
host = ["0.0.0.0:6306"]
# 数据库操作超时时间
timeout = 5  # 秒为单位
# 前端文件路径
view_path = "./view"

# etcd
[etcd]
service = ["0.0.0.0:2379"]
username = ""
password = ""
dialtimeout = 5000
# etcd kv存储的key前缀 用来与其他业务做区分
prefix = "/gopher_cron"

[mysql]
service="0.0.0.0:3306"
username=""
password=""
database=""

# jwt用来做api的身份校验
[jwt]
# jwt签名的secret 建议修改
secret = "fjskfjls2ifeew2mn"
exp = 168  # token 有效期(小时)

service 部署

$ ./service -conf ./conf/config-default.toml // 配置文件名请随意  
2019-01-18 00:00:45 listening and serving HTTP on 0.0.0.0:6306

client 配置文件

log_level = "debug"

[deploy]
# 当前的环境:dev、release
environment = "release"
# 数据库操作超时时间
timeout = 5  # 秒为单位

# etcd
[etcd]
service = ["0.0.0.0:2379"]
username = ""
password = ""
dialtimeout = 5000
# etcd kv存储的key前缀 用来与其他业务做区分
prefix = "/gopher_cron"
# 当前节点需要处理的项目ID
projects = [1,2]
# 命令调用脚本 /bin/sh  /bin/bash 根据自己系统情况决定
shell = "/bin/bash"

[mysql]
service="0.0.0.0:3306"
username=""
password=""
database=""

client 部署

$ ./client -conf ./conf/config-default.toml
// 等待如下输入即启动成功 
register key /gopher_cron/register/12/xxx.xxx.xxx.xxx

Admin 管理页面

访问地址: localhost:6306/admin

管理员初始账号密码为 admin 123456

image

image

注意

client配置文件中的project配置需要用户先部署service
在service中创建项目后可以获得项目ID
需要将项目ID填写在client的配置中该client才会调度这个项目的任务

About

golang 开箱即用的秒级分布式定时任务系统


Languages

Language:Go 99.6%Language:Shell 0.4%