diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-07 23:52:11 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-07 23:54:26 +0200 |
| commit | b2cdc03c3bfc21ffcb43f6636d2ec761eb6a6f25 (patch) | |
| tree | 12368eea325138383f10df0f94e27217ea2d1689 | |
| parent | 78f4b0cc54f1a877f4e53f1a21b01f8c2791c9d1 (diff) | |
| download | shrinker-b2cdc03c3bfc21ffcb43f6636d2ec761eb6a6f25.tar.gz shrinker-b2cdc03c3bfc21ffcb43f6636d2ec761eb6a6f25.zip | |
attempt to fix race condition
| -rw-r--r-- | worker.js | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -55,7 +55,7 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI, // fill queue until batchsize or idle if (timer === undefined) - timer = setTimeout(process, IDLE_TIMEOUT) + timer = setTimeout(process, IDLE_TIMEOUT); if (queue.length == BATCHSIZE) await process(); }, { noAck: false }); @@ -64,10 +64,10 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI, console.log("processing batch", queue.length); // clean up to allow processor to accept while we wait for db - let msgs = queue.slice(); - queue = []; clearTimeout(timer); timer = undefined; + let msgs = queue; + queue = []; // helper to convert API response into flat JSON // db structure is (almost) 1:1 the API structure @@ -212,8 +212,8 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI, try { console.log("inserting batch into db"); // upsert whole batch in parallel - await seq.transaction({ autocommit: false }, (transaction) => { - return Promise.all([ + await seq.transaction({ autocommit: false }, async (transaction) => { + await Promise.all([ model.Match.bulkCreate(match_records, { include: [ model.Roster, model.Asset ], updateOnDuplicate: [], // all |
