Switch to central config loader using mounted secret files.
This commit is contained in:
15
src/index.ts
15
src/index.ts
@@ -5,6 +5,8 @@ import { processAndStore } from './sss.js'
|
||||
import { getLatestPackageName, getRequestStream } from './sources/gitea.js'
|
||||
import { processPisStream } from './process.js'
|
||||
import { isPackageProcessed } from './database.js'
|
||||
import { ConfigLoader } from './config.js'
|
||||
import { sendFileUpdateMessage } from './nats.js'
|
||||
|
||||
async function main() {
|
||||
const SERVICE_NAME = process.env.SERVICE_NAME;
|
||||
@@ -13,6 +15,8 @@ async function main() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const config = ConfigLoader();
|
||||
|
||||
try {
|
||||
const packageInfo = await getLatestPackageName();
|
||||
log('INFO', `Latest PIS Package: ${packageInfo.name}`);
|
||||
@@ -22,20 +26,25 @@ async function main() {
|
||||
process.exit(9);
|
||||
}
|
||||
|
||||
if (await isPackageProcessed(SERVICE_NAME, packageInfo.name)) {
|
||||
if (await isPackageProcessed(config.Mongo, SERVICE_NAME, packageInfo.name)) {
|
||||
log('INFO', `Database matches latest release. Exiting`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const inputStream: Readable = await getRequestStream(packageInfo.assets[0].browser_download_url);
|
||||
const objectGenerator = processPisStream(inputStream);
|
||||
const objectGenerator = processPisStream(config.General, inputStream);
|
||||
|
||||
const filename = `${packageInfo.name.replace(/\s+/g, '_')}_pis_data_ndjson`;
|
||||
|
||||
log('DEBUG', `Processing stream to: ${filename}`);
|
||||
|
||||
await processAndStore(objectGenerator, filename);
|
||||
await processAndStore(config.S3, objectGenerator, filename);
|
||||
log('DEBUG', 'Done');
|
||||
|
||||
log('DEBUG', "Sending message to NATS");
|
||||
sendFileUpdateMessage(config.Mq, filename, packageInfo.name, SERVICE_NAME);
|
||||
log('DEBUG', "Done, exiting")
|
||||
return
|
||||
} catch (err) {
|
||||
log('ERROR', 'Fatal error in pipeline: ', err);
|
||||
process.exit(7);
|
||||
|
||||
Reference in New Issue
Block a user