diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-07-24 22:00:30 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-07-24 22:00:30 +0200 |
| commit | fbc3d9ddb8ad310bc787c2c47ee9b23163decd95 (patch) | |
| tree | 20efbd20a698128541535b178514b13faf1e3082 | |
| parent | 53fbb647b1053f88e2d37dadb72a9ca5ecccbb1a (diff) | |
| download | bridge-fbc3d9ddb8ad310bc787c2c47ee9b23163decd95.tar.gz bridge-fbc3d9ddb8ad310bc787c2c47ee9b23163decd95.zip | |
add a route to crunch all player points
| -rw-r--r-- | service_crunch.js | 33 | ||||
| -rw-r--r-- | service_skeleton.js | 2 |
2 files changed, 14 insertions, 21 deletions
diff --git a/service_crunch.js b/service_crunch.js index 1197114..71fd9f2 100644 --- a/service_crunch.js +++ b/service_crunch.js @@ -27,6 +27,11 @@ module.exports = class Cruncher extends Service { this.crunchGlobal(req.params.category || "regular"); res.sendStatus(204); }, + // crunch all players + "/api/player/crunch/:category*?": async (req, res) => { + this.crunchGlobal(req.params.category || "regular", true); + res.sendStatus(204); + }, // crunch a player "/api/player/:name/crunch/:category*?": async (req, res) => { const category = req.params.category || "regular", @@ -42,20 +47,6 @@ module.exports = class Cruncher extends Service { players.forEach((player) => this.crunchPlayer(category, player.api_id)); // fire away res.sendStatus(204); - }, - // crunch a team - "/api/team/:id/crunch": async (req, res) => { - const db = this.getDatabase("regular"), - team = await db.Team.findOne({ where: { id: req.params.id } }); - if (team == undefined) { - logger.error("team not found in db, won't crunch", - { name: req.params.id }); - res.sendStatus(404); - return; - } - logger.info("team in db, crunching", { name: team.id }); - crunchTeam(team.id); // fire away - res.sendStatus(204); } }); } @@ -81,11 +72,13 @@ module.exports = class Cruncher extends Service { } // crunch global stats - async crunchGlobal(category) { - const db = this.getDatabase(category); + async crunchGlobal(category, is_player=false) { + const db = this.getDatabase(category), + key_name = "global_last_crunch_participant_id" + (is_player?"_player":""), + target = category + (is_player?"_player":""); + console.log("getting key", category, key_name); // get lcpid from keys table - let last_crunch_participant_id = await this.getKey(category, - "global_last_crunch_participant_id", 0); + let last_crunch_participant_id = await this.getKey(category, key_name, 0); // don't load the whole Participant table at once into memory let participations; @@ -102,13 +95,13 @@ module.exports = class Cruncher extends Service { order: [ ["id", "ASC"] ] }); await Promise.map(participations, async (p) => - await this.forward(this.getTarget(category), p.api_id, + await this.forward(this.getTarget(target), p.api_id, { persistent: true })); // update lpcid & refetch if (participations.length > 0) { last_crunch_participant_id = participations[participations.length-1].id; - await this.setKey(category, "global_last_crunch_participant_id", + await this.setKey(category, key_name, last_crunch_participant_id); } logger.info("loading more participations into cruncher", { diff --git a/service_skeleton.js b/service_skeleton.js index 1dc9a3b..f94020c 100644 --- a/service_skeleton.js +++ b/service_skeleton.js @@ -17,7 +17,7 @@ module.exports = class Service { } getDatabase(category) { if (!this.dbs.has(category)) - logger.error("unsupported database category"); + logger.error("unsupported database category", category); return this.dbs.get(category); } |
