vjudge: better sync method

This commit is contained in:
undefined committed 2021-06-27 23:30:05 +08:00
1 parent 7bdf580e7d
commit 1139c0ea57
4 files changed
+8 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/vjudge", "name": "@hydrooj/vjudge",
"version": "1.0.13", "version": "1.0.14",
"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",
+1 -1
View File
@@ -25,7 +25,7 @@ export interface IBasicProvider {
tag: string[]; tag: string[];
content: string; content: string;
}>; }>;
listProblem(page: number): Promise<string[]>; listProblem(page: number, resync: boolean): Promise<string[]>;
submitProblem(id: string, lang: string, code: string, info): Promise<string>; submitProblem(id: string, lang: string, code: string, info): Promise<string>;
waitForSubmission(id: string, next: any, end: any): Promise<void>; waitForSubmission(id: string, next: any, end: any): Promise<void>;
} }
+4 -3
View File
@@ -32,9 +32,9 @@ class Service {
await this.api.waitForSubmission(rid, next, end); await this.api.waitForSubmission(rid, next, end);
} }
async sync(domainId: string) { async sync(domainId: string, resync = false) {
let page = 1; let page = 1;
let pids = await this.api.listProblem(page); let pids = await this.api.listProblem(page, resync);
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) {
@@ -68,7 +68,8 @@ class Service {
TaskModel.consume({ type: 'remotejudge', subType: this.account.type }, this.judge.bind(this)); TaskModel.consume({ type: 'remotejudge', subType: this.account.type }, this.judge.bind(this));
const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray(); const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray();
for (const ddoc of ddocs) { for (const ddoc of ddocs) {
if (!ddoc.syncDone) await this.sync(ddoc._id); if (!ddoc.syncDone) await this.sync(ddoc._id, false);
else await this.sync(ddoc._id, true);
await DomainModel.edit(ddoc._id, { syncDone: true }); await DomainModel.edit(ddoc._id, { syncDone: true });
} }
} }
+2 -1
View File
@@ -182,7 +182,8 @@ export default class CodeforcesProvider implements IBasicProvider {
}; };
} }
async listProblem(page: number) { async listProblem(page: number, resync = false) {
if (resync && page > 1) return [];
const res = await this.get(`/problemset/page/${page}`); const res = await this.get(`/problemset/page/${page}`);
const $dom = new JSDOM(res.text); const $dom = new JSDOM(res.text);
const index = $dom.window.document.querySelector('.page-index.active').getAttribute('pageindex'); const index = $dom.window.document.querySelector('.page-index.active').getAttribute('pageindex');