Answers for "loopback cronjob"

2

loopback cron job

npm install --save @loopback/cron
...
// Start by importing the component class:
import {CronComponent} from '@loopback/cron';

// In the constructor, add the component to your application:
this.component(CronComponent);
...
import {CronJob, asCronJob} from '@loopback/cron';

// Create an cron job
const job = new CronJob({
	cronTime: '*/1 * * * * *', // Every one second
    onTick: () => {
		// Do the work
	},
	start: true, // Start the job immediately
});

// Bind the cron job as an extension for the scheduler
app.bind('cron.jobs.job1').to(job).apply(asCronJob);
Posted by: Guest on October-14-2020

Browse Popular Code Answers by Language