diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2018-05-05 13:52:50 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2018-05-05 13:52:50 +0200 |
| commit | 63da93e9f443a799208c8e706616a828fa528a3e (patch) | |
| tree | e0d540555cdca710645efb0ce061742ec55c8ec6 /params.js | |
| parent | c8dc06971c6dab447250bb81cca20836ed5b2772 (diff) | |
| download | brokentalents-63da93e9f443a799208c8e706616a828fa528a3e.tar.gz brokentalents-63da93e9f443a799208c8e706616a828fa528a3e.zip | |
move request param generation to own file, retry failed queries
Diffstat (limited to 'params.js')
| -rw-r--r-- | params.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/params.js b/params.js new file mode 100644 index 0000000..b3dcb98 --- /dev/null +++ b/params.js @@ -0,0 +1,37 @@ +#!/usr/bin/node + +const R = require('ramda'); + +function paramsForHourSample(config) { + const requestArgsForRegionStartEnd = R.curry((region, start, end) => [ + `/shards/${region}/matches`, { + 'sort': '-createdAt', + 'filter[gameMode]': R.join(',', config.modes), + 'filter[createdAt-start]': start.toISOString(), + 'filter[createdAt-end]': end.toISOString(), + 'page[limit]': '5', + 'page[offset]': '0', + } + ]); + + const requestsPerMinutePerRegion = Math.floor(config.rpm / config.regions.length); + const splitDurationMinutes = Math.floor(60 / requestsPerMinutePerRegion); + const splitMoments = (hour) => R.map( + (offsetIndex) => [ + hour.clone().startOf('hour').minutes(offsetIndex * splitDurationMinutes), + hour.clone().startOf('hour').minutes((offsetIndex + 1) * splitDurationMinutes), + ], + R.range(0, requestsPerMinutePerRegion), + ); + + return R.pipe( + splitMoments, + R.xprod(config.regions), + R.map(R.unnest), + R.map(R.apply(requestArgsForRegionStartEnd)), + ); +} + +module.exports = { + paramsForHourSample, +}; |
