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 * @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) } }) }