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