fastify-schedule

Fastify plugin for scheduling periodic jobs

Usage no npm install needed!

<script type="module">
  import fastifySchedule from 'https://cdn.skypack.dev/fastify-schedule';
</script>

README

fastify-schedule

NPM Version Build Status Coverage Status

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 { fastifySchedulePlugin } = require('fastify-schedule')
const fastify = require('fastify');

fastify.register(fastifySchedulePlugin);

From there jobs can be added to scheduler at any point until the application is stopped:

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 */ }
)
const job = new SimpleIntervalJob({ seconds: 20, }, task)

fastify.scheduler.addSimpleIntervalJob(job)

For more detailed instructions, see the documentation of toad-scheduler.