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.

64 lines
1.3 KiB

3 years ago
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