Moleculer Cron
install
$ npm install @john-ko/moleculer-crons
usage
import { ServiceSchema } from 'moleculer'
import CronMixin, { CronJobSchema } from '@john-ko/moleculer-crons'
const broker = new ServiceBroker()
const schema = {
name: 'cron-test',
mixins: [CronMixin]
crons: {
test: {
cronTime: '* * * * *',
onTick: async function () {
console.log('starting cronjob...')
const total = await this.broker.call('math.add', { a: 1, b: 2})
console.log(total)
},
}
},
}
broker.createService(schema)
broker.start()
full options
const schema = {
name: 'cron-test',
mixins: [CronMixin]
crons: {
namedCronJob: {
cronTime: string | Date | DateTime;
onTick: CronCommand;
onComplete?: CronCommand | null | undefined;
start?: boolean | undefined;
timeZone?: string | undefined;
context?: any;
runOnInit?: boolean | undefined;
utcOffset?: string | number | undefined;
unrefTimeout?: boolean | undefined;
}
}
}