@fastify/schedule
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -17,4 +17,4 @@ const { ToadScheduler } = require("toad-scheduler"); | ||
const fastifySchedulePlugin = fp(plugin, { | ||
fastify: "3.x", | ||
name: "fastify-schedule", | ||
fastify: "4.x", | ||
name: "@fastify/schedule", | ||
}); | ||
@@ -21,0 +21,0 @@ |
{ | ||
"name": "@fastify/schedule", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Fastify plugin for scheduling periodic jobs", | ||
@@ -18,3 +18,3 @@ "license": "MIT", | ||
"test:typescript": "tsd", | ||
"lint": "eslint --format codeframe \"lib/**/*.js\" \"test/**/*.js\" index.js", | ||
"lint": "eslint \"lib/**/*.js\" \"test/**/*.js\" index.js", | ||
"lint:everything": "npm run lint && npm run test:typescript", | ||
@@ -30,3 +30,3 @@ "prettier": "prettier --write \"{lib,test}/**/*.js\" index.js index.d.ts", | ||
"peerDependencies": { | ||
"fastify": "^3.0.0", | ||
"fastify": "^4.0.0-rc.3", | ||
"toad-scheduler": "^1.0.2" | ||
@@ -40,3 +40,3 @@ }, | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"fastify": "^3.10.1", | ||
"fastify": "^4.0.0-rc.3", | ||
"husky": "^8.0.0", | ||
@@ -50,5 +50,2 @@ "jest": "^26.6.3", | ||
}, | ||
"engines": { | ||
"node": ">=10.16.0" | ||
}, | ||
"homepage": "http://github.com/fastify/fastify-schedule", | ||
@@ -55,0 +52,0 @@ "repository": { |
@@ -1,6 +0,5 @@ | ||
# fastify-schedule | ||
# @fastify/schedule | ||
![CI](https://github.com/fastify/fastify-schedule/workflows/CI/badge.svg) | ||
[![NPM Version][npm-image]][npm-url] | ||
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-schedule/badge.svg)](https://snyk.io/test/github/fastify/fastify-schedule) | ||
[![Coverage Status](https://coveralls.io/repos/fastify/fastify-schedule/badge.svg?branch=main)](https://coveralls.io/r/fastify/fastify-schedule?branch=main) | ||
@@ -17,3 +16,3 @@ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier) | ||
```bash | ||
npm i fastify-schedule toad-scheduler | ||
npm i @fastify/schedule toad-scheduler | ||
``` | ||
@@ -24,21 +23,20 @@ | ||
```js | ||
const { fastifySchedulePlugin } = require('fastify-schedule') | ||
const fastify = require('fastify'); | ||
const fastify = require('fastify')(); | ||
const { fastifySchedulePlugin } = require('@fastify/schedule'); | ||
const { SimpleIntervalJob, AsyncTask } = require('toad-scheduler'); | ||
fastify.register(fastifySchedulePlugin); | ||
``` | ||
From there jobs can be added to scheduler at any point until the application is stopped: | ||
```js | ||
const { SimpleIntervalJob, AsyncTask } = require('toad-scheduler') | ||
const task = new AsyncTask( | ||
'simple task', | ||
() => { return db.pollForSomeData().then((result) => { /* continue the promise chain */ }) }, | ||
(err: Error) => { /* handle errors here */ } | ||
(err) => { /* handle errors here */ } | ||
) | ||
const job = new SimpleIntervalJob({ seconds: 20, }, task) | ||
fastify.scheduler.addSimpleIntervalJob(job) | ||
fastify.register(fastifySchedulePlugin); | ||
// `fastify.scheduler` becomes available after initialization. | ||
// Therefore, you need to call `ready` method. | ||
fastify.ready().then(() => { | ||
fastify.scheduler.addSimpleIntervalJob(job) | ||
}) | ||
``` | ||
@@ -48,3 +46,3 @@ | ||
[npm-image]: https://img.shields.io/npm/v/fastify-schedule.svg | ||
[npm-url]: https://npmjs.org/package/fastify-schedule | ||
[npm-image]: https://img.shields.io/npm/v/@fastify/schedule.svg | ||
[npm-url]: https://npmjs.org/package/@fastify/schedule |
5992
46