Skip to content

Commit

Permalink
use fs to get file
Browse files Browse the repository at this point in the history
  • Loading branch information
sdobbert authored and sdobbert committed Feb 20, 2024
1 parent 35d0359 commit 2f03e73
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/create-contour/contour.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const createContourLines = async (inputPath, datasetTimestamp, interval) => {
}

// build command for sub-process
const contourCmd = `gdal_contour -b 2 -a TEMP -i ${interval} -f "GeoJSON" ${inputPath} /opt/cog/output${datasetTimestamp}.geojson`;
const contourCmd = `gdal_contour -b 2 -a TEMP -i ${interval} -f "GeoJSON" ${inputPath} /tmp/output${datasetTimestamp}.geojson`;

return await execShellCommand(contourCmd);
}
Expand Down
28 changes: 11 additions & 17 deletions src/create-contour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { initialize } from '../workerTemplate.js';
import logger from './child-logger.js';
import { getClient } from './get-client.js';
import { addData } from './add-to-table.js'
import fetch from 'node-fetch';
import * as fs from 'fs/promises';

import dayjs from 'dayjs';
Expand Down Expand Up @@ -45,10 +44,17 @@ const contourLinesWorker = async (workerJob, inputs) => {

// array aus multiLines als geoJSON
// todo check if it needs a relative path
const file = `https://klips-dev.terrestris.de/cog/output${datasetTimestampUnformated}.geojson`;
const contourLines = fetch(file)
.then((response) => response.json())
.then(data => { return (data) });
const file = `/tmp/output${datasetTimestampUnformated}.geojson`;
let contourLines;
fs.readFile(file, (err, data) => {
if (err) throw err;
contourLines = data;
});

if (!contourLines) {
logger.error(`Contour lines could not be fetched.`);
throw `Contour lines could not be fetched.`;
}

// Create table
// TODO check if this can be moved to seperate file
Expand Down Expand Up @@ -76,18 +82,6 @@ const contourLinesWorker = async (workerJob, inputs) => {
region
));

//Delete temporal file
if (!contourLines) {
logger.error(`Contour lines could not be fetched.`);
throw `Contour lines could not be fetched.`;
}

try {
await fs.unlink(file);
} catch (error) {
logger.error({ error: error }, `Problem deleting file.`);
}

workerJob.status = 'success';

logger.info(`Archiving finished.`);
Expand Down
85 changes: 0 additions & 85 deletions src/create-contour/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/create-contour/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dotenv": "^16.4.1",
"fs": "^0.0.1-security",
"node": "^21.6.1",
"node-fetch": "^3.3.2",
"pg": "^8.11.3",
"pino": "^8.8.0",
"pino-pretty": "^9.1.1"
Expand Down

0 comments on commit 2f03e73

Please sign in to comment.