import dayjs from 'dayjs' import Db from './_db.ts' import Docket from './_docket.ts' import { resolveActionClass } from './helpers/resolver.ts' import logger from './helpers/logger.ts' /** * run through a single config, getting each action with config * and run them, the docket will be used to hold data and configs * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License * @link https://git.node001.net/HerrHase/super-hog.git * */ async function run(config: object) { let db = new Db(config.slug) let docket = new Docket(config, db) logger(config.slug).info('has started') for (const actionConfig of config.actions) { // resolve action class const ActionClass = await import(resolveActionClass(actionConfig.class)) // options are exists, add to docket if (actionConfig.hasOwnProperty('options')) { docket.setOptions(action.options) } try { const action = new ActionClass.default(docket) logger(config.slug).info('action / ' + actionConfig.class) await action.run() docket = action.getDocket() } catch(error) { logger(config.slug).error('action / ' + actionConfig.class + ' / ' + error) } } logger(config.slug).info('has finished') // update db await db.update({ 'date_run_at': dayjs().toISOString() }) return docket } export default run