Browse Source

Workaround Sequelize's .save() possibly won't resolve bug

master
Menci 6 years ago
parent
commit
3ae5262797
  1. 3
      models/common.js
  2. 13
      utility.js

3
models/common.js

@ -34,7 +34,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();

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