# @reinjs/rein-schedule

> project of reinjs

Latest version **1.0.2** (published 2018-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @reinjs/rein-schedule
pnpm add @reinjs/rein-schedule
yarn add @reinjs/rein-schedule
bun add @reinjs/rein-schedule
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-07-24 |
| First published | 2018-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | reinjs |
| Maintainers | reinjs |

## Links

- npm: https://www.npmjs.com/package/@reinjs/rein-schedule
- Repository: https://github.com/reinjs/rein-schedule
- Homepage: https://github.com/reinjs/rein-schedule#readme
- Issues: https://github.com/reinjs/rein-schedule/issues
- npm.io page: https://npm.io/package/@reinjs/rein-schedule

## Dependencies (4)

- [is-type-of](https://npm.io/package/is-type-of.md) ^1.2.0
- [node-schedule](https://npm.io/package/node-schedule.md) ^1.3.0
- [@reinjs/rein-class](https://npm.io/package/@reinjs/rein-class.md) ^1.0.2
- [@reinjs/rein-loader](https://npm.io/package/@reinjs/rein-loader.md) ^1.0.4

## Recent versions

- 1.0.2 (latest) — 2018-07-24
- 1.0.1 — 2018-05-25
- 1.0.0 — 2018-05-24

## README

# rein-schedule

## Install

```shell
npm i @reinjs/rein-schedule
```

## Usage

在项目文件夹或者插件文件夹中会存在一个文件夹 `schedule`，下面所有的文件都将被认为是一个任务，任务必须存在2个属性或方法：

- **rule** `object`或者`string` 时间规则 参考 https://www.npmjs.com/package/node-schedule#cron-style-scheduling
- **task** `function` 执行逻辑

比如我们创建一个任务 `app/schedule/test/db.js`:

```javascript
const Schedule = require('@reinjs/rein-schedule');

module.exports = class DbSchedule extends Schedule {
  constructor(...args) {
    super(...args);
  }

  /**
   * 此属性可以直接用字符串表示
   * 比如 `return '0 17 ? * 0,4-6'`
   */
  rule() {
    const rule = new Schedule.RecurrenceRule();
    rule.dayOfWeek = [0, new Schedule.Range(4, 6)];
    rule.hour = 17;
    rule.minute = 0;
    return rule;
  }

  async task() {
    // this.app do something.
  }
}
```

- 获取方式 `app.schedule.test.db`，遵守`reinjs`约定都规范。
- 取消任务 `await app.schedule.test.db.cancel()`

> **注意** 此插件只允许使用在`agent`进程上

# License

It is [MIT licensed](https://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/@reinjs/rein-schedule · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
