0.4.0 • Published 2 years ago

@pimred/cron v0.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

@pimred/cron

Schedule cronjobs with nodejs and log results to elasticsearch.

Installation

npm install @pimred/cron

Usage

Run a generic command.

const Scheduler = require('@pimred/cron')
const scheduler = new Scheduler()

scheduler.addCronjob({
    crontime: '* * * * *', // See https://crontab.guru/
    name: 'name of the cronjob',
    description: 'optional description',
    command: () => {
        console.log('Cronjob command fired')
    }
})

Call a http request.

const Scheduler = require('@pimred/cron')
const scheduler = new Scheduler()

scheduler.addHttpCronjob({
    crontime: '* * * * *', 
    name: 'name of the cronjob', 
    url: 'https://www.wirth-horn.de',
    options: {} // axios options
})

Execute a cronjob after another

const Scheduler = require('@pimred/cron')
const scheduler = new Scheduler()

scheduler.addCronjob({
    crontime: '* * * * *', // See https://crontab.guru/
    name: 'name of the parent cronjob',
    description: 'optional description',
    command: () => {
        console.log('Cronjob command fired')
    }
})

scheduler.addCronjobAfer('name of the parent cronjob', {
    name: 'name of the child cronjob',
    description: 'optional description',
    command: () => {
        console.log('I am executed after a parent cronjob')
    }
})

scheduler.addHttpCronjobAfter('name of the parent cronjob', {
    name: 'name of the child http cronjob', 
    url: 'https://www.wirth-horn.de'
})

Pause a cronjob

scheduler.pauseCronjob('name of the cronjob')

Resume a cronjob

scheduler.resumeCronjob('name of the cronjob')

Remove a cronjob

scheduler.removeCronjob('name of the cronjob')

Monitoring

@pimred/cron will log the cronjob execution to elasticsearch.

Development: https://elasticstack-01.atelier.wirth-horn.de:5601

Production: https://elasticstack-01.do.pimred.cloud:5601

Specifiy elastic options

const Scheduler = require('@pimred/cron')
const scheduler = new Scheduler({
    elasticOptions: {
        // https://www.npmjs.com/package/@pimred/logger
        indexName: 'cron'
    }
})
0.4.0

2 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.1.0

4 years ago