diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-10 19:25:08 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-10 19:25:08 +0200 |
| commit | c95146410694ea67f8916af1c5d31fe710876f40 (patch) | |
| tree | 4e9bf9e5f49844a673a9fa1ff478069ba17dd607 | |
| parent | 4f7f7ec8f1f912c031b0dc3700d184f24a9818c9 (diff) | |
| download | cruncher-c95146410694ea67f8916af1c5d31fe710876f40.tar.gz cruncher-c95146410694ea67f8916af1c5d31fe710876f40.zip | |
deduplicate jobs in a batch
| -rw-r--r-- | worker.js | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -129,18 +129,23 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI, queue = []; let player_records = [], - global_records = []; + global_records = [], + players_done = [], + global_done = false; await Promise.all(msgs.map(async (msg) => { - if (msg.properties.type == "global") { + if (msg.properties.type == "global" && global_done == false) { // TODO let stats = await calculate_global_point(); if (stats != undefined) global_records.push(stats); } if (msg.properties.type == "player") { - let stats = await calculate_player_point( - msg.content.toString()); - if (stats != undefined) player_records.push(stats); + let player_id = msg.content.toString(); + if (players_done.indexOf(player_id) == -1) { + players_done.push(player_id); + let stats = await calculate_player_point(player_id); + if (stats != undefined) player_records.push(stats); + } } })); |
