UNPKG

@fastify/schedule

Version:

Fastify plugin for scheduling periodic jobs

26 lines (19 loc) 564 B
'use strict' const { ToadScheduler } = require('toad-scheduler') const fp = require('fastify-plugin') function plugin (fastify, _opts, next) { const scheduler = new ToadScheduler() fastify.decorate('scheduler', scheduler) fastify.addHook('onClose', (_fastify, done) => { scheduler.stop() done() }) next() } const fastifySchedulePlugin = fp(plugin, { fastify: '5.x', name: '@fastify/schedule' }) module.exports = fastifySchedulePlugin module.exports.default = fastifySchedulePlugin module.exports.fastifySchedule = fastifySchedulePlugin