A Dexare module for managing crons.
npm install @dexare/cron
const { DexareClient } = require('dexare');
const CronModule = require('@dexare/cron');
const config = {
cron: {
loadFolder: './src/crons'
}
}
const client = new DexareClient(config);
client.loadModules(CronModule);
const cron = client.modules.get('cron');
cron.registerFromFolder('./src/crons');
cron.register({
name: 'example-cron',
time: '0 * * * *',
onTick: (client, job) => {
console.log(`This cron executed at ${job.lastDate}`)
}
});
Cron File Example
This example cron flushes throttle data within memory data managers.
Options are the same as CronJob's constructor parameters, except a new parameter name
must be given to identify the job, and context
will not be used in the construction of a new cron job.
module.exports = {
name: 'flush-throttles',
time: '0 * * * *',
onTick: (client, job) => {
this.client.data.flushThrottles()
}
}