DefinitelyTyped/types/node-cron/node-cron-tests.ts
maximelkin f69b0ea7b6 add @types/node-cron (#23062)
* add node-cron

* Update tslint.json

Remove lint rule
2018-01-23 10:43:37 -08:00

48 lines
995 B
TypeScript

/// <reference types="node" />
import cron = require('node-cron');
// tslint:disable-next-line no-console
const log = console.log;
cron.schedule('* * * * *', () => {
log('running a task every minute');
});
cron.schedule('1-5 * * * *', () => {
log('running every minute to 1 from 5');
});
// tslint:disable-next-line rule
const task = cron.schedule('* * * * *', () => {
log('immediately started');
// because of manual call start method
}, false);
task.start();
const task1 = cron.schedule('* * * * *', () => {
log('will execute every minute until stopped');
});
task1.start();
const task2 = cron.schedule('* * * * *', () => {
log('will execute every minute until stopped');
});
task2.stop();
const task3 = cron.schedule('* * * * *', () => {
log('will execute every minute until stopped');
});
task3.destroy();
const valid = cron.validate('59 * * * *');
const invalid = cron.validate('60 * * * *');
if (valid && !invalid) {
log('validator works');
}