Make scraping host configurable

remotes/1711448277524916210/master
Sven Slootweg 3 years ago
parent 78a0c5a051
commit dd7ef4ae97

@ -6,9 +6,15 @@ const path = require("path");
const defaultValue = require("default-value"); const defaultValue = require("default-value");
const moize = require("moize"); const moize = require("moize");
const config = require("../config.json");
const knex = require("knex")(require("../knexfile")); const knex = require("knex")(require("../knexfile"));
const createSynchronizer = require("./sync")({ knex: knex }); let state = {
knex: knex,
scrapingHost: config.scrapingHost
};
const createSynchronizer = require("./sync")(state);
createSynchronizer("datasheets_products", "datasheet:", (item) => { createSynchronizer("datasheets_products", "datasheet:", (item) => {
if (item.data.url != null) { if (item.data.url != null) {

@ -4,9 +4,12 @@ const Promise = require("bluebird");
const matchValue = require("match-value"); const matchValue = require("match-value");
const pipe = require("@promistream/pipe"); const pipe = require("@promistream/pipe");
const simpleSink = require("@promistream/simple-sink"); const simpleSink = require("@promistream/simple-sink");
const updateStream = require("./update-stream");
module.exports = function ({ knex }) { module.exports = function (state) {
const updateStream = require("./update-stream")(state);
let { knex } = state;
return function createSynchronizer(tableName, prefix, mapper, { getLastTimestamp } = {}) { return function createSynchronizer(tableName, prefix, mapper, { getLastTimestamp } = {}) {
return Promise.try(() => { return Promise.try(() => {
if (getLastTimestamp != null) { if (getLastTimestamp != null) {

@ -12,7 +12,8 @@ const fromNodeStream = require("@promistream/from-node-stream");
const createNDJSONParseStream = require("./ndjson-parse-stream"); const createNDJSONParseStream = require("./ndjson-parse-stream");
module.exports = function createUpdateStream({ since, prefix } = {}) { module.exports = function({ scrapingHost }) {
return function createUpdateStream({ since, prefix } = {}) {
let lastTimestamp = since ?? new Date(0); let lastTimestamp = since ?? new Date(0);
return pipe([ return pipe([
@ -22,7 +23,7 @@ module.exports = function createUpdateStream({ since, prefix } = {}) {
// To ensure that we don't hammer the srap instance // To ensure that we don't hammer the srap instance
return Promise.delay(5 * 1000); return Promise.delay(5 * 1000);
}).then(() => { }).then(() => {
return bhttp.get(`http://localhost:3000/updates?prefix=${encodeURIComponent(prefix)}&since=${Math.floor(lastTimestamp.getTime())}`, { return bhttp.get(`http://${scrapingHost}/updates?prefix=${encodeURIComponent(prefix)}&since=${Math.floor(lastTimestamp.getTime())}`, {
stream: true stream: true
}); });
}).then((response) => { }).then((response) => {
@ -59,3 +60,4 @@ module.exports = function createUpdateStream({ since, prefix } = {}) {
}) })
]); ]);
}; };
};

Loading…
Cancel
Save