import Interface from 'es6-interface' import RequestHandlerInterface from './requestHandlerInterface.js' import ResolverClass from './../helpers/resolverClass.js' /** * * * * */ class RequestHandler extends Interface(RequestHandlerInterface) { /** * * @param {[type]} source * */ constructor(source) { super() this.source = source } /** * process actions that are saved in a source * * * @param {object} data * */ async processActions(data) { let errors = false this.source.actions.forEach(async (actions) => { const resolverClass = new ResolverClass('actions') const classPath = resolverClass.find(actions.className) // import class from action const Action = await import(classPath) // create action an call run const action = new Action.default(this.source, data, actions.options) // if (!await action.run()) { errors = true } }) // if errors if (errors && this.source.errors < 5) { this.source.errors++ } else { this.source.last_run_at = new Date() } } } export default RequestHandler