mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
vjudge: prevent race cond
This commit is contained in:
1 parent
577e100ca6
commit
ce3cdc645c
2 files changed
+17
-11
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/vjudge",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "Submit problems to remote oj",
|
"description": "Submit problems to remote oj",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { BasicProvider, IBasicProvider, RemoteAccount } from './interface';
|
|||||||
const coll = db.collection('vjudge');
|
const coll = db.collection('vjudge');
|
||||||
const Pool = {};
|
const Pool = {};
|
||||||
const logger = new Logger('vjudge');
|
const logger = new Logger('vjudge');
|
||||||
|
const syncing = {};
|
||||||
|
|
||||||
class Service {
|
class Service {
|
||||||
api: IBasicProvider;
|
api: IBasicProvider;
|
||||||
@@ -37,17 +38,22 @@ class Service {
|
|||||||
while (pids.length) {
|
while (pids.length) {
|
||||||
logger.info(`${domainId}: Syncing page ${page}`);
|
logger.info(`${domainId}: Syncing page ${page}`);
|
||||||
for (const pid of pids) {
|
for (const pid of pids) {
|
||||||
if (await ProblemModel.get(domainId, pid)) continue;
|
if (syncing[`${domainId}/${pid}`] || await ProblemModel.get(domainId, pid)) continue;
|
||||||
const res = await this.api.getProblem(pid);
|
syncing[`${domainId}/${pid}`] = true;
|
||||||
if (!res) continue;
|
try {
|
||||||
const id = await ProblemModel.add(domainId, pid, res.title, res.content, 1, res.tag, false);
|
const res = await this.api.getProblem(pid);
|
||||||
for (const key in res.files) {
|
if (!res) continue;
|
||||||
await ProblemModel.addAdditionalFile(domainId, id, key, res.files[key]);
|
const id = await ProblemModel.add(domainId, pid, res.title, res.content, 1, res.tag, false);
|
||||||
|
for (const key in res.files) {
|
||||||
|
await ProblemModel.addAdditionalFile(domainId, id, key, res.files[key]);
|
||||||
|
}
|
||||||
|
for (const key in res.data) {
|
||||||
|
await ProblemModel.addTestdata(domainId, id, key, res.data[key]);
|
||||||
|
}
|
||||||
|
logger.info(`${domainId}: problem ${id} sync done`);
|
||||||
|
} finally {
|
||||||
|
delete syncing[`${domainId}/${pid}`];
|
||||||
}
|
}
|
||||||
for (const key in res.data) {
|
|
||||||
await ProblemModel.addTestdata(domainId, id, key, res.data[key]);
|
|
||||||
}
|
|
||||||
logger.info(`${domainId}: problem ${id} sync done`);
|
|
||||||
await sleep(5000);
|
await sleep(5000);
|
||||||
}
|
}
|
||||||
page++;
|
page++;
|
||||||
|
|||||||
Reference in new issue
Block a user