@fastify/schedule
TypeScript icon, indicating that this package has built-in type declarations

4.1.1 • Public • Published

@fastify/schedule

CI NPM version NPM downloads js-standard-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 { fastifySchedulePlugin } = 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 of toad-scheduler.

Package Sidebar

Install

npm i @fastify/schedule

Weekly Downloads

5,190

Version

4.1.1

License

MIT

Unpacked Size

5.25 kB

Total Files

5

Last publish

Collaborators

  • gurgunday
  • metcoder95
  • galvez
  • simenb
  • coopflow
  • simoneb
  • rafaelgss
  • starptech
  • delvedor
  • matteo.collina
  • allevo
  • jsumners
  • zekth
  • eomm
  • fox1t
  • airhorns
  • kibertoad
  • climba03003
  • is2ei
  • fdawgs