core: fix index creation (#197)

pull/199/head
undefined 3 years ago
parent 62dbd0beb8
commit f5c63e02ce

@ -28,8 +28,6 @@ class JudgeTask {
host: string;
request: any;
ws: WebSocket;
tag: any;
type: any;
domainId: string;
pid: string;
rid: string;
@ -59,8 +57,6 @@ class JudgeTask {
this.next = this.next.bind(this);
this.end = this.end.bind(this);
this.stat.handle = new Date();
this.tag = this.request.tag;
this.type = this.request.type;
this.domainId = this.request.pdomain;
this.pid = this.request.pid.toString();
this.rid = this.request.rid;

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.34.3",
"version": "2.34.4",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",

@ -69,7 +69,10 @@ class WorkerService implements BaseService {
async (doc) => {
try {
logger.debug('Worker task: %o', doc);
const start = Date.now();
await this.handlers[doc.subType](doc);
const spent = Date.now() - start;
if (spent > 500) logger.warn('Slow worker task (%d ms): %s', spent, doc);
} catch (e) {
logger.error('Worker task fail: ', e);
logger.error('%o', doc);

@ -50,7 +50,12 @@ class MongoService implements BaseService {
public async ensureIndexes<T>(coll: Collection<T>, ...args: IndexSpecification[]) {
if (process.env.NODE_APP_INSTANCE !== '0') return;
const existed = await coll.listIndexes().toArray();
let existed: any[];
try {
existed = await coll.listIndexes().toArray();
} catch (e) {
existed = [];
}
for (const index of args) {
const i = existed.find(t => t.name == index.name || JSON.stringify(t.key) == JSON.stringify(index.key));
if (!i) {

Loading…
Cancel
Save