Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fastify/fastify-schedule
Fastify plugin for scheduling periodic jobs.
https://github.com/fastify/fastify-schedule
fastify fastify-plugin
Last synced: 4 days ago
JSON representation
Fastify plugin for scheduling periodic jobs.
- Host: GitHub
- URL: https://github.com/fastify/fastify-schedule
- Owner: fastify
- License: mit
- Created: 2021-01-18T22:32:14.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-30T11:35:02.000Z (4 months ago)
- Last Synced: 2024-10-29T14:46:55.695Z (3 months ago)
- Topics: fastify, fastify-plugin
- Language: JavaScript
- Homepage:
- Size: 104 KB
- Stars: 92
- Watchers: 18
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @fastify/schedule
[![CI](https://github.com/fastify/fastify-schedule/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-schedule/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/schedule.svg?style=flat)](https://www.npmjs.com/package/@fastify/schedule)
[![NPM downloads](https://img.shields.io/npm/dm/@fastify/schedule.svg?style=flat)](https://www.npmjs.com/package/@fastify/schedule)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)Fastify plugin for scheduling periodic jobs. Provides an instance of [toad-scheduler](https://github.com/kibertoad/toad-scheduler) on fastify instance.
Jobs are stopped automatically when the fastify instance is stopped.## Getting started
First install the package:
```bash
npm i @fastify/schedule toad-scheduler
```Next, set up the plugin:
```js
const fastify = require('fastify')();
const { fastifySchedule } = require('@fastify/schedule');
const { SimpleIntervalJob, AsyncTask } = require('toad-scheduler');const task = new AsyncTask(
'simple task',
() => { return db.pollForSomeData().then((result) => { /* continue the promise chain */ }) },
(err) => { /* handle errors here */ }
)
const job = new SimpleIntervalJob({ seconds: 20, }, task)fastify.register(fastifySchedulePlugin);
// `fastify.scheduler` becomes available after initialization.
// Therefore, you need to call `ready` method.
fastify.ready().then(() => {
fastify.scheduler.addSimpleIntervalJob(job)
})
```For more detailed instructions, see the [documentation](https://github.com/kibertoad/toad-scheduler) of `toad-scheduler`.