You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
import cron from 'node-cron'
|
|
|
|
import { resolveEnabledConfig } from './helpers/resolver.ts'
|
|
import logger from './helpers/logger.ts'
|
|
|
|
import run from './_run.ts'
|
|
|
|
/**
|
|
* Run all Configs that are in Directory /resources/configs/enabled
|
|
*
|
|
* @author Björn Hase <me@herr-hase.wtf>
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://git.node001.net/HerrHase/super-hog.git
|
|
*
|
|
*/
|
|
|
|
// get all configs from resolveEnabledConfig
|
|
const configs = resolveEnabledConfig()
|
|
|
|
// check if there is any valid config
|
|
if (configs.length === 0) {
|
|
throw new Error('No valid config found!')
|
|
}
|
|
|
|
// running through configs
|
|
for (const index in configs) {
|
|
|
|
const config = configs[index]
|
|
|
|
// check for cron
|
|
if (!config.hasOwnProperty('cron')) {
|
|
continue
|
|
}
|
|
|
|
/**
|
|
* adding task to schedule, using cron
|
|
*
|
|
*/
|
|
const task = cron.schedule(config.cron, async() => {
|
|
try {
|
|
const docket = await run(config, docket)
|
|
} catch(error) {
|
|
logger(config.slug).error(error)
|
|
}
|
|
})
|
|
}
|