Add retry functionality

This commit is contained in:
1computer1 2019-05-21 11:50:16 -04:00
parent d40264f521
commit 030f24be24
2 changed files with 9 additions and 5 deletions

View file

@ -14,5 +14,6 @@
"memory": "256m", "memory": "256m",
"cpus": "0.25", "cpus": "0.25",
"timeout": 10000, "timeout": 10000,
"concurrent": 10 "concurrent": 10,
"retries": 2
} }

View file

@ -111,7 +111,7 @@ class LanguageHandler extends AkairoHandler {
} }
} }
evalCode({ language, code, options }) { evalCode({ language, code, options, retries = 0 }) {
const { id: dockerID = language.id, env = {} } = language.runWith(options); const { id: dockerID = language.id, env = {} } = language.runWith(options);
const queue = this.queues.get(dockerID); const queue = this.queues.get(dockerID);
return queue.enqueue(async () => { return queue.enqueue(async () => {
@ -132,9 +132,12 @@ class LanguageHandler extends AkairoHandler {
try { try {
await this.kill(name); await this.kill(name);
} catch (err2) { } catch (err2) {
// Kill did not work, usually this is because of the container being killed just before. // The container was not alive to be killed, i.e. multiple evals were occuring,
// Happens when evals are done in quick succession and the container can't handle it. // one of them caused the container to be killed, the remaining evals all fail.
// Solution is to lower the concurrent setting for that compiler. // Retry those remaining ones until they work!
if (retries < this.getCompilerConfig(dockerID, 'retries', 'number')) {
return this.evalCode({ language, code, options, retries: retries + 1 });
}
} }
throw err; throw err;