mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: codeforces: add rate limit
This commit is contained in:
1 file changed
+9
-3
@@ -295,7 +295,7 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
const message = Array.from(statusDocument.querySelectorAll('.error'))
|
const message = Array.from(statusDocument.querySelectorAll('.error'))
|
||||||
.map((i) => i.textContent).join('').replace(/ /g, ' ').trim();
|
.map((i) => i.textContent).join('').replace(/ /g, ' ').trim();
|
||||||
if (message) {
|
if (message) {
|
||||||
end({ status: STATUS.STATUS_COMPILE_ERROR, message });
|
end({ status: STATUS.STATUS_SYSTEM_ERROR, message });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const { document } = await this.html(type !== 'GYM'
|
const { document } = await this.html(type !== 'GYM'
|
||||||
@@ -308,6 +308,7 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
|
|
||||||
async waitForSubmission(id: string, next, end) {
|
async waitForSubmission(id: string, next, end) {
|
||||||
let i = 1;
|
let i = 1;
|
||||||
|
const start = Date.now();
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
await sleep(3000);
|
await sleep(3000);
|
||||||
@@ -319,13 +320,14 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
submissionId: contestId ? id.split('#')[1] : id,
|
submissionId: contestId ? id.split('#')[1] : id,
|
||||||
});
|
});
|
||||||
if (body.compilationError === 'true') {
|
if (body.compilationError === 'true') {
|
||||||
return await end({
|
await end({
|
||||||
compilerText: body['checkerStdoutAndStderr#1'],
|
compilerText: body['checkerStdoutAndStderr#1'],
|
||||||
status: STATUS.STATUS_COMPILE_ERROR,
|
status: STATUS.STATUS_COMPILE_ERROR,
|
||||||
score: 0,
|
score: 0,
|
||||||
time: 0,
|
time: 0,
|
||||||
memory: 0,
|
memory: 0,
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
const time = Math.sum(Object.keys(body).filter((k) => k.startsWith('timeConsumed#')).map((k) => +body[k]));
|
const time = Math.sum(Object.keys(body).filter((k) => k.startsWith('timeConsumed#')).map((k) => +body[k]));
|
||||||
const memory = Math.max(...Object.keys(body).filter((k) => k.startsWith('memoryConsumed#')).map((k) => +body[k])) / 1024;
|
const memory = Math.max(...Object.keys(body).filter((k) => k.startsWith('memoryConsumed#')).map((k) => +body[k])) / 1024;
|
||||||
@@ -344,12 +346,16 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
if (cases.length) await next({ status: STATUS.STATUS_JUDGING, cases });
|
if (cases.length) await next({ status: STATUS.STATUS_JUDGING, cases });
|
||||||
if (body.waiting === 'true') continue;
|
if (body.waiting === 'true') continue;
|
||||||
const status = VERDICT[Object.keys(VERDICT).find((k) => normalize(body.verdict).includes(k))];
|
const status = VERDICT[Object.keys(VERDICT).find((k) => normalize(body.verdict).includes(k))];
|
||||||
return await end({
|
await end({
|
||||||
status,
|
status,
|
||||||
score: status === STATUS.STATUS_ACCEPTED ? 100 : 0,
|
score: status === STATUS.STATUS_ACCEPTED ? 100 : 0,
|
||||||
time,
|
time,
|
||||||
memory,
|
memory,
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
// TODO better rate limiting
|
||||||
|
// Codeforces only allow 20 submission per 5 minute
|
||||||
|
if (Date.now() - start < 16000) await sleep(Date.now() - start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user