egg-cluster-schedule

1.0.4 • Public • Published

egg-cluster-schedule

egg 定时任务分布式调度插件,防止集群定时任务重复执行多次。

QuickStart

1. 安装

npm i egg-cluster-schedule

2. 配置

/config/config.{default}.js

config.agenda = {
  db: {
    address: 'mongodb://127.0.0.1/test', // 必填项, mongodb 地址
    collection: 'egg-cluster-schedule-jobs'
  },
  defaultLockLifetime: 60 * 1000,
}

3.启用插件

/config/plugin.js

exports.clusterSchedule = {
  enable: true,
  package: 'egg-cluster-schedule',
};

4.改造现有 schedule

/app/schedule/xxx.js

module.exports = {
  schedule: {
    type: 'cluster', // type 改成 cluster 即可, 其他配置保持不变
    //... 
  },
  async task(ctx) {
    // 执行的任务 ctx.service.xxx()
    // ...
  }
}

更多资料

Readme

Keywords

none

Package Sidebar

Install

npm i egg-cluster-schedule

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

7.44 kB

Total Files

12

Last publish

Collaborators

  • zhironghao