summaryrefslogtreecommitdiff
path: root/backend/source.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2018-05-07 09:06:04 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2018-05-07 09:06:04 +0200
commit5caf4e48174533710243e8eeaf52567795ec9d01 (patch)
tree1396f09bd14c3c4e1af3164ef924f2190b3f949f /backend/source.js
parentded191658af266a764332b9a1b72d628de3d5b6e (diff)
downloadbrokentalents-5caf4e48174533710243e8eeaf52567795ec9d01.tar.gz
brokentalents-5caf4e48174533710243e8eeaf52567795ec9d01.zip
move files to backend subdir, push data in submodule
Diffstat (limited to 'backend/source.js')
-rw-r--r--backend/source.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/backend/source.js b/backend/source.js
new file mode 100644
index 0000000..0f4fd28
--- /dev/null
+++ b/backend/source.js
@@ -0,0 +1,39 @@
+#!/usr/bin/node
+
+const R = require('ramda'),
+ Future = require('fluture'),
+ etl = require('./etl'),
+ params = require('./params'),
+ reduce = require('./reduce'),
+ file = require('./file');
+
+function doFetchProcessStoreHour(config) {
+ const intervalSleep = 60 / config.api.intervalsPerMinute * 1000;
+
+ const paramsForHourSample = params.paramsForHourSample(config.api);
+ const loadFApi = etl.loadFPayloads(config.etl);
+ const saveFPayloads = file.saveFPayloadsTimestamped(config.file);
+ const aggregatePayloads = reduce.aggregatePayloads(config.reduce);
+
+ const requestsForHour = (timestamp) => R.map(R.apply(loadFApi), paramsForHourSample(timestamp));
+
+ return (timestamp) => Future.parallel(1, requestsForHour(timestamp))
+ .map(R.compose(aggregatePayloads, R.unnest))
+ .chainRej((err) => { console.error(err); return Future.of({}); }) // fail silently
+ .chain(saveFPayloads(timestamp));
+ //.chain(Future.after(intervalSleep));
+ // TODO should sleep after request; throttling rpm should happen
+ // at a higher level though. CPU / IO / AWS requests stall
+ // as well
+}
+
+function loadFTimestamped(config) {
+ // load from file or fall back to API and store
+ return (timestamp) =>
+ file.loadFPayloads(config)(config.file.pattern(timestamp))
+ .or(doFetchProcessStoreHour(config)(timestamp));
+};
+
+module.exports = {
+ loadFTimestamped,
+};