Fix languages that have more than one compiler
This commit is contained in:
parent
b31f4dfb21
commit
71079ceb19
1 changed files with 20 additions and 20 deletions
|
@ -54,50 +54,50 @@ class LanguageHandler extends AkairoHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildDocker() {
|
buildDocker() {
|
||||||
return Promise.all(this.modules.map(({ id, loads }) => {
|
return Promise.all(this.modules.map(({ loads }) => {
|
||||||
return Promise.all(loads.map(async name => {
|
return Promise.all(loads.map(async dockerID => {
|
||||||
const folder = path.join(__dirname, '../../docker', name);
|
const folder = path.join(__dirname, '../../docker', dockerID);
|
||||||
await util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${name}" ${folder}`);
|
await util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${dockerID}" ${folder}`);
|
||||||
this.queues.set(id, new Queue(10));
|
this.queues.set(dockerID, new Queue(10));
|
||||||
if (this.client.config.prepare) {
|
if (this.client.config.prepare) {
|
||||||
await this.setupContainer(id);
|
await this.setupContainer(dockerID);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupContainer(id) {
|
async setupContainer(dockerID) {
|
||||||
if (this.containers.has(id)) {
|
if (this.containers.has(dockerID)) {
|
||||||
return this.containers.get(id);
|
return this.containers.get(dockerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = `comp_iler-${id}-${Date.now()}`;
|
const name = `comp_iler-${dockerID}-${Date.now()}`;
|
||||||
const proc = childProcess.spawn('docker', [
|
const proc = childProcess.spawn('docker', [
|
||||||
'run', '--rm', `--name=${name}`, '-u1000', '-w/tmp/', '-t', '-d',
|
'run', '--rm', `--name=${name}`, '-u1000', '-w/tmp/', '-t', '-d',
|
||||||
'--net=none', `--cpus=${this.client.config.cpus}`,
|
'--net=none', `--cpus=${this.client.config.cpus}`,
|
||||||
`-m=${this.client.config.memory}`, `--memory-swap=${this.client.config.memory}`,
|
`-m=${this.client.config.memory}`, `--memory-swap=${this.client.config.memory}`,
|
||||||
`1computer1/comp_iler:${id}`
|
`1computer1/comp_iler:${dockerID}`
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.handleSpawn(proc);
|
await this.handleSpawn(proc);
|
||||||
this.containers.set(id, { name, count: 0 });
|
this.containers.set(dockerID, { name, count: 0 });
|
||||||
return this.containers.get(id);
|
return this.containers.get(dockerID);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementCount(id) {
|
incrementCount(dockerID) {
|
||||||
this.containers.get(id).count += 1;
|
this.containers.get(dockerID).count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
evalCode({ language, code, options }) {
|
evalCode({ language, code, options }) {
|
||||||
const { id = language.id, env = {} } = language.runWith(options);
|
const { id: dockerID = language.id, env = {} } = language.runWith(options);
|
||||||
const queue = this.queues.get(id);
|
const queue = this.queues.get(dockerID);
|
||||||
return queue.enqueue(async () => {
|
return queue.enqueue(async () => {
|
||||||
const { name, count } = await this.setupContainer(id);
|
const { name, count } = await this.setupContainer(dockerID);
|
||||||
this.incrementCount(id);
|
this.incrementCount(dockerID);
|
||||||
|
|
||||||
const proc = childProcess.spawn('docker', [
|
const proc = childProcess.spawn('docker', [
|
||||||
'exec',
|
'exec',
|
||||||
|
@ -110,7 +110,7 @@ class LanguageHandler extends AkairoHandler {
|
||||||
const result = await this.handleSpawn(proc);
|
const result = await this.handleSpawn(proc);
|
||||||
return result;
|
return result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.containers.delete(id);
|
this.containers.delete(dockerID);
|
||||||
await this.kill(name);
|
await this.kill(name);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue