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.

58 lines
1.5 KiB

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 <me@herr-hase.wtf>
* @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