Skip to content

About

Fastify plugin for scheduling periodic jobs

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

117 stars

Watchers

13 watching

Forks

Latest commit

 

History

178 Commits

Folders and files

Repository files navigation

@fastify/schedule

CI NPM version NPM downloads neostandard javascript style

Fastify plugin for scheduling periodic jobs. Provides an instance of toad-scheduler on fastify instance. Jobs are stopped automatically when the fastify instance is stopped.

Getting started

First install the package:

npm i @fastify/schedule toad-scheduler

Next, set up the plugin:

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(fastifySchedule);

// `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 of toad-scheduler.

About

Fastify plugin for scheduling periodic jobs

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

117 stars

Watchers

13 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages