Update sync server to use refactored API

master
Sven Slootweg 2 years ago
parent 6e172dd04d
commit dbd15aa1d7

@ -31,8 +31,7 @@ const { testValue } = require("@validatem/core");
const matchesFormat = require("@validatem/matches-format"); const matchesFormat = require("@validatem/matches-format");
const isString = require("@validatem/is-string"); const isString = require("@validatem/is-string");
const initialize = require("../src/initialize"); const createKernel = require("../src/kernel");
const errors = require("../src/errors");
let argv = yargs.argv; let argv = yargs.argv;
let configurationPath = argv._[0]; let configurationPath = argv._[0];
@ -43,20 +42,8 @@ let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {
// FIXME: Deduplicate this with kernel! Also other common wiring across binaries... return createKernel(configuration);
return initialize({ }).then((kernel) => {
knexfile: {
client: "pg",
connection: configuration.database,
pool: { min: 0, max: 32 },
migrations: { tableName: "srap_knex_migrations" }
}
});
}).then((state) => {
let { db, knex } = state;
const queries = require("../src/queries")(state);
let app = express(); let app = express();
let router = expressPromiseRouter(); let router = expressPromiseRouter();
@ -125,7 +112,7 @@ return Promise.try(() => {
: undefined; : undefined;
return pipe([ return pipe([
queries.getUpdates(knex, { prefix: req.query.prefix, timestamp: timestamp }), kernel.getUpdates({ prefix: req.query.prefix, timestamp }),
map((item) => JSON.stringify(item) + "\n"), map((item) => JSON.stringify(item) + "\n"),
fromNodeStream(res) fromNodeStream(res)
]).read(); ]).read();

@ -126,6 +126,9 @@ module.exports = async function createKernel(_configuration) {
metrics: metrics metrics: metrics
}; };
}); });
},
getUpdates: function ({ prefix, timestamp }) {
return backend.topLevel.getUpdateStream(null, { prefix, timestamp });
} }
}; };
}; };

Loading…
Cancel
Save