forked from OSMCha/osm-adiff-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·39 lines (32 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
'use strict';
const zlib = require('zlib');
const util = require('util');
const gunzip = util.promisify(zlib.gunzip);
const { getChangesets } = require('./lib/get-changesets');
const { uploadToS3 } = require('./lib/s3');
const { postTagChanges } = require('./lib/tagChanges');
const { formatReplicationKey } = require('./util/format-replication-key');
const { request } = require('./util/request');
const { s3 } = require('./lib/s3-client');
const { REPLICATION_BUCKET } = require('./lib/constants');
process.on('unhandledRejection', (up) => { throw up; });
process.on('exit', (code) => {
console.log(`Exit with code: ${code}`);
});
const run = async (replicationFileId) => {
console.time(`TIME ${replicationFileId}`);
const { Body } = await s3.getObject({
Bucket: REPLICATION_BUCKET,
Key: formatReplicationKey(replicationFileId)
}).promise();
const xmlBin = await gunzip(Body);
const changesets = await getChangesets(xmlBin.toString());
const changesetList = Object.values(changesets);
await Promise.all(changesetList.map(uploadToS3));
console.log('Uploaded all changesets to s3');
await Promise.all(changesetList.map(postTagChanges));
console.log('Posted all changesets tagChanges to OSMCha API');
console.timeEnd(`TIME ${replicationFileId}`);
};
module.exports = run;