Browse Source

Merge pull request #1 from syzoj/master

Sync with mainline
pull/6/head
Menci 6 years ago committed by GitHub
parent
commit
80560aa20f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app.js
  2. 3
      models/common.js
  3. 4
      modules/problem.js
  4. 13
      utility.js

8
app.js

@ -22,6 +22,14 @@ global.syzoj = {
console.log(obj);
},
async run() {
// Check config
if (syzoj.config.session_secret === '@SESSION_SECRET@'
|| syzoj.config.email_jwt_secret === '@EMAIL_JWT_SECRET@'
|| syzoj.config.db.password === '@DATABASE_PASSWORD@') {
console.log('Please generate and fill the secrets in config!');
process.exit();
}
let Express = require('express');
global.app = Express();

3
models/common.js

@ -36,7 +36,8 @@ class Model {
for (let key in obj) this.record.set(key, obj[key]);
let isNew = this.record.isNewRecord;
await this.record.save();
await syzoj.utils.withTimeoutRetry(() => this.record.save());
if (!isNew) return;
await this.reload();

4
modules/problem.js

@ -683,7 +683,9 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code: formatted
});
await formattedCode.save();
try {
await formattedCode.save();
} catch (e) {}
}
}
}

13
utility.js

@ -294,5 +294,18 @@ module.exports = {
async saveConfig() {
let fs = require('fs-extra');
fs.writeFileAsync(syzoj.configDir, JSON.stringify(syzoj.config, null, 2));
},
withTimeoutRetry(func) {
let attemptCount = 0;
return new Promise((resolve, reject) => {
function attempt() {
if (attemptCount++) console.log(`syzoj.utils.withTimeout(): attemptCount = ${attemptCount}`);
Promise.method(func)().timeout(5000)
.then(resolve)
.catch(Promise.TimeoutError, attempt)
.catch(reject);
}
attempt();
});
}
};

Loading…
Cancel
Save