diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-10 18:42:44 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-10 18:42:44 +0200 |
| commit | 54c4b0d05c5d3a288bb3a3a7810667b13048bbb0 (patch) | |
| tree | 10a76378acb1c61eeb028e02c33b92b755cd2c54 | |
| parent | 231211e94e5019714b306bb406fb55dd2c5e268e (diff) | |
| download | shrinker-54c4b0d05c5d3a288bb3a3a7810667b13048bbb0.tar.gz shrinker-54c4b0d05c5d3a288bb3a3a7810667b13048bbb0.zip | |
optionally send crunch jobs only for gamers
| -rw-r--r-- | worker.js | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -12,7 +12,10 @@ var amqp = require("amqplib"), var RABBITMQ_URI = process.env.RABBITMQ_URI, DATABASE_URI = process.env.DATABASE_URI, BATCHSIZE = parseInt(process.env.BATCHSIZE) || 2 * 50 * (1 + 5), // matches + players - IDLE_TIMEOUT = parseFloat(process.env.IDLE_TIMEOUT) || 1000; // ms + IDLE_TIMEOUT = parseFloat(process.env.IDLE_TIMEOUT) || 1000, // ms + PREMIUM_FEATURES = process.env.PREMIUM_FEATURES || false; // calculate on demand for non-premium users + +console.log("features for premium users activated", PREMIUM_FEATURES); (async () => { let seq, model, rabbit, ch; @@ -61,6 +64,10 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI, .map((role) => role_db_map[role.name] = role.id) ]); + // TODO expire this cache after some time + let premium_users = (await model.Gamer.findAll()).map((gamer) => + gamer.name); + // as long as the queue is filled, msg are not ACKed // server sends as long as there are less than `prefetch` unACKed await ch.prefetch(BATCHSIZE); @@ -331,12 +338,14 @@ var RABBITMQ_URI = process.env.RABBITMQ_URI, type: "participant" }) )); - Promise.all(player_records.map(async (p) => - await ch.sendToQueue("crunch", new Buffer(p.api_id), { - persistent: true, - type: "player" - }) - )); + Promise.all(player_records.map(async (p) => { + if (PREMIUM_FEATURES == false || premium_users.indexOf(p.name) != -1) { + await ch.sendToQueue("crunch", new Buffer(p.api_id), { + persistent: true, + type: "player" + }) + } + })); } // Split participant API data into participant and participant_stats |
