Skip to content

A distributed scheduling system based on Node.js (back)

Notifications You must be signed in to change notification settings

iblueio/timecloud-back

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iBlue

timecloud-back

A distributed scheduling system based on Node.js (back)

Features

  • 任务监控界面,线上浏览日志

  • 任务超时控制

  • 防止单点故障

  • 微信报警通知

  • 任务失败后,使用信号SIGUSR2通知任务进程,请在指定时间内处理自己的任务并使进程退出

  • 每个进程同一时间内只执行一个任务,进程满载后其余任务进入任务队列(可在监控界面查看)

  • 任务失败或超时会自动重试(次数默认为2次),当失败时会发通知,通知频率和crontab一样

Timecloud

Table of Contents generated with DocToc

Create Job


1) Interface

在自己的项目文件下添加timecloud.json文件

{
  "jobs": [
    {
      "name": "npm",
      "script": "npm start",
      "maintainer": "user",
      "timeout": 5000,
      "schedule": "*/30 * * * * *"
    },
    {
      "name": "start",
      "script": "./bin/start",
      "maintainer": "user",
      "timeout": 30000,
      "schedule": "0 * * * * *"
    },
    {
      "name": "update",
      "script": "./bin/update",
      "maintainer": ["user1", "user2"],
      "timeout": 40000,
      "schedule": "0 0 * * * *"
    }
  ]
}

当任务出错或超时后,timecloud会往进程传递SIGUSR2信号,请监听该信号并在5秒内处理自己的任务,避免不必要的损失。

process.on('SIGUSR2', async () => {
  await doSomethingImportant()
  process.exit(0)
})

参数说明

name: 任务名称

script: 将要执行的脚本,可以是npm start, 或./bin目录下的脚本(注意脚本执行指令的正确写法,前面要有一点)

maintainer: 任务失败后会发送任务告警信息, user为需要通知的用户

schedule: 即crontab

* * * * * *
| | | | | | 
| | | | | +-- Day of the Week   (range: 0-6, 0 standing for Monday)
| | | | +---- Month             (range: 0-11)
| | | +------ Day of the Month  (range: 1-31)
| | +-------- Hour              (range: 0-23)
| +---------- Minute            (range: 0-59)
+------------ Second            (range: 0-59)

timeout:任务超时判断,超时后即判定任务失败

2) Deploy

使用timecloud-scripts部署任务

TODO

3) Watch logs

进入任务监控界面即可看到日志按钮

Local debug

  • 在timecloud路径下执行npm i

  • 将你的包放在home目录下的npm文件夹里,要有timecloud.json文件

  • 开启本地MongoDB

  • 在timecloud路径下执行ENV=dev npm start即可

  • pm2日志输出在home目录下的log文件夹里

  • 停止任务输入npm stop

  • 任务监控界面在localhost:19031

About

A distributed scheduling system based on Node.js (back)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published