feat(core): init interpreter class + constructor
This commit is contained in:
@@ -29,3 +29,54 @@ interface InterpreterOptions {
|
|||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for running the Smart Workflows.
|
||||||
|
*/
|
||||||
|
export default class Interpreter extends EventEmitter {
|
||||||
|
private workflow: Workflow;
|
||||||
|
|
||||||
|
private initializedWorkflow: Workflow | null;
|
||||||
|
|
||||||
|
private options: InterpreterOptions;
|
||||||
|
|
||||||
|
private concurrency : Concurrency;
|
||||||
|
|
||||||
|
private stopper : Function | null = null;
|
||||||
|
|
||||||
|
private log : typeof log;
|
||||||
|
|
||||||
|
constructor(workflow: WorkflowFile, options?: Partial<InterpreterOptions>) {
|
||||||
|
super();
|
||||||
|
this.workflow = workflow.workflow;
|
||||||
|
this.initializedWorkflow = null;
|
||||||
|
this.options = {
|
||||||
|
maxRepeats: 5,
|
||||||
|
maxConcurrency: 5,
|
||||||
|
serializableCallback: (data) => { log(JSON.stringify(data), Level.WARN); },
|
||||||
|
binaryCallback: () => { log('Received binary data, thrashing them.', Level.WARN); },
|
||||||
|
debug: false,
|
||||||
|
debugChannel: {},
|
||||||
|
...options,
|
||||||
|
};
|
||||||
|
this.concurrency = new Concurrency(this.options.maxConcurrency);
|
||||||
|
this.log = (...args) => log(...args);
|
||||||
|
|
||||||
|
const error = Preprocessor.validateWorkflow(workflow);
|
||||||
|
if (error) {
|
||||||
|
throw (error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.debugChannel?.debugMessage) {
|
||||||
|
const oldLog = this.log;
|
||||||
|
// @ts-ignore
|
||||||
|
this.log = (...args: Parameters<typeof oldLog>) => {
|
||||||
|
if (args[1] !== Level.LOG) {
|
||||||
|
this.options.debugChannel.debugMessage!(typeof args[0] === 'string' ? args[0] : args[0].message);
|
||||||
|
}
|
||||||
|
oldLog(...args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user