feat: enhance DatabaseManagerService and QueryExecuterService with timeout settings, add AxiosPlugin for HTTP requests, and update DatabasePlugin to use query method

This commit is contained in:
Boris D
2025-10-09 17:20:33 +03:00
parent 0631e99886
commit 5b30b876e5
7 changed files with 104 additions and 13 deletions

View File

@ -10,15 +10,21 @@ export class Vm {
private jail: any;
private plugins: Plugin[];
private isolate: ivm.Isolate;
private timeLimit?: bigint;
private cpuTimeLimit?: bigint;
constructor(configs: {
memoryLimit: number;
timeLimit?: bigint;
cpuTimeLimit?: bigint;
modules: VModule[];
plugins: Plugin[];
}) {
this.memoryLimit = configs.memoryLimit;
this.modules = configs.modules;
this.plugins = configs.plugins;
this.timeLimit = configs.timeLimit;
this.cpuTimeLimit = configs.cpuTimeLimit;
}
async init(): Promise<Vm> {
@ -111,11 +117,23 @@ export class Vm {
const compiledScript = await this.isolate.compileScript(scriptWithResult);
const interval = setInterval(() => {
if (
this.isolate.cpuTime > this.cpuTimeLimit ||
this.isolate.wallTime > this.timeLimit
) {
this.isolate.dispose();
rejectPromise(new Error("Script execution timed out"));
}
}, 500);
compiledScript.run(this.context);
try {
return await resultPromise;
} finally {
clearInterval(interval);
this.onFinish();
}
}