core&judge: log download errors

This commit is contained in:
undefined committed 2022-10-30 12:55:46 +08:00
1 parent d1a652d364
commit 7d6b1f3bbc
4 files changed
+18 -6

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "3.1.3", "version": "3.1.4",
"main": "package.json", "main": "package.json",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
@@ -14,9 +14,9 @@
"mongodb": "^3.7.3", "mongodb": "^3.7.3",
"p-queue": "^7.3.0", "p-queue": "^7.3.0",
"schemastery": "^3.5.4", "schemastery": "^3.5.4",
"shell-quote": "^1.7.3", "shell-quote": "^1.7.4",
"superagent": "^8.0.2", "superagent": "^8.0.2",
"ws": "^8.9.0" "ws": "^8.10.0"
}, },
"preferUnplugged": true, "preferUnplugged": true,
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
+13 -2
View File
@@ -54,6 +54,9 @@ export default class Hydro {
await Lock.acquire(`${this.config.host}/${source}`); await Lock.acquire(`${this.config.host}/${source}`);
try { try {
return await this._cacheOpen(source, files, next); return await this._cacheOpen(source, files, next);
} catch (e) {
log.warn('CacheOpen Fail: %s %o %o', source, files, e);
throw e;
} finally { } finally {
Lock.release(`${this.config.host}/${source}`); Lock.release(`${this.config.host}/${source}`);
} }
@@ -87,14 +90,22 @@ export default class Hydro {
pid: +pid, pid: +pid,
files: filenames, files: filenames,
}); });
if (!res.body.links) throw new FormatError('problem not exist');
// eslint-disable-next-line no-inner-declarations // eslint-disable-next-line no-inner-declarations
async function download(name: string) { async function download(name: string) {
if (name.includes('/')) await fs.ensureDir(path.join(filePath, name.split('/')[0])); if (name.includes('/')) await fs.ensureDir(path.join(filePath, name.split('/')[0]));
const w = fs.createWriteStream(path.join(filePath, name)); const w = fs.createWriteStream(path.join(filePath, name));
this.get(res.body.links[name]).pipe(w); this.get(res.body.links[name]).pipe(w);
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
w.on('finish', resolve); const timeout = setTimeout(() => reject(new Error(`DownloadTimeout(${name}, 60s)`)), 60000);
w.on('error', (e) => reject(new Error(`DownloadFail(${name}): ${e.message}`))); w.on('error', (e) => {
clearTimeout(timeout);
reject(new Error(`DownloadFail(${name}): ${e.message}`));
});
w.on('finish', () => {
clearTimeout(timeout);
resolve(null);
});
}); });
} }
const tasks = []; const tasks = [];
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "4.2.15", "version": "4.2.16",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/plugin-api", "main": "src/plugin-api",
"module": "src/plugin-api", "module": "src/plugin-api",
+1
View File
@@ -151,6 +151,7 @@ export class JudgeFilesDownloadHandler extends Handler {
@post('pid', Types.UnsignedInt) @post('pid', Types.UnsignedInt)
async post(domainId: string, files: Set<string>, pid: number) { async post(domainId: string, files: Set<string>, pid: number) {
const pdoc = await problem.get(domainId, pid); const pdoc = await problem.get(domainId, pid);
if (!pdoc) this.response.body.links = null;
const links = {}; const links = {};
for (const file of files) { for (const file of files) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop