summaryrefslogtreecommitdiff
path: root/worker.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-04-25 14:48:22 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-04-25 14:48:22 +0200
commit78820b25d29d754ead3328d63119ccb2ec01db6b (patch)
tree34a00de5666b4f6b84ff0273c569c8867b1c6324 /worker.js
parentba8c9ce4bf2e23336c7bb8539c4fdb92f943e614 (diff)
downloadcruncher-78820b25d29d754ead3328d63119ccb2ec01db6b.tar.gz
cruncher-78820b25d29d754ead3328d63119ccb2ec01db6b.zip
split between global and player crunches
Diffstat (limited to 'worker.js')
-rw-r--r--worker.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/worker.js b/worker.js
index 8ab445a..8c06d63 100644
--- a/worker.js
+++ b/worker.js
@@ -73,7 +73,7 @@ if (LOGGLY_TOKEN)
// fill a buffer and execute an SQL on a bigger (> 1o) batch
const participants_player = new Set(),
- participants = new Set(),
+ participants_global = new Set(),
// store the msgs that should be ACKed
buffer = new Set();
let timeout = undefined;
@@ -83,9 +83,9 @@ if (LOGGLY_TOKEN)
ch.consume("crunch", (msg) => {
const api_id = msg.content.toString();
if (msg.properties.type == "global")
- participants.add(api_id);
- // else exclusively add data to player, used for player refresh
- participants_player.add(api_id);
+ participants_global.add(api_id);
+ if (msg.properties.type == "player")
+ participants_player.add(api_id);
buffer.add(msg);
if (timeout == undefined) timeout = setTimeout(crunch, LOAD_TIMEOUT*1000);
if (buffer.size >= BATCHSIZE) crunch();
@@ -98,17 +98,17 @@ if (LOGGLY_TOKEN)
// prevent async issues
const api_ids_player = [...participants_player],
- api_ids = [...participants],
+ api_ids_global = [...participants_global],
msgs = new Set(buffer);
- participants.clear();
+ participants_global.clear();
participants_player.clear();
buffer.clear();
clearTimeout(timeout);
timeout = undefined;
- if (api_ids.length > 0)
+ if (api_ids_global.length > 0)
await seq.query(global_script, {
- replacements: { participant_api_ids: api_ids },
+ replacements: { participant_api_ids: api_ids_global },
type: seq.QueryTypes.UPSERT
});
if (api_ids_player.length > 0)
@@ -123,7 +123,7 @@ if (LOGGLY_TOKEN)
// TODO notify for player too
await ch.publish("amq.topic", "global", new Buffer("points_update"));
- profiler.done("crunched");
+ profiler.done("crunched", { size: msgs.size });
}
})();