Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove db connection #233

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions src/geoserver-create-and-apply-sld/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {GeoServerRestClient} from 'geoserver-node-client';
import { initialize } from '../workerTemplate.js';
import logger from './child-logger.js';
import pg from 'pg';
const { Client } = pg;
import * as fs from 'fs/promises';
import { exec } from 'child_process';

const url = process.env.GEOSERVER_REST_URL;
Expand All @@ -13,11 +12,6 @@ const resultQueue = process.env.RESULTSQUEUE;
const rabbitHost = process.env.RABBITHOST;
const rabbitUser = process.env.RABBITUSER;
const rabbitPass = process.env.RABBITPASS;
const pgpasswd = process.env.POSTGRES_PASSWORD;
const pghost = process.env.POSTGRES_HOST;
const pgport = process.env.POSTGRES_PORT;
const pguser = process.env.POSTGRES_USER;
const pgdb = process.env.POSTGRES_DB;
const grc = new GeoServerRestClient(url, user, pw);

/**
Expand All @@ -33,16 +27,16 @@ const grc = new GeoServerRestClient(url, user, pw);
"inputs": [
"myCustomStyleName",
"mySldWorkspace",
"myCoverageDbTable",
"myBand"
"myBand",
"myFilePathtoTheCOGWebspace"
]
}
*/
const geoServerCreateAndApplySld = async (workerJob, inputs) => {
const sldName = inputs[0];
const sldWorkspace = inputs[1];
const dbTable = inputs[2];
const band = inputs[3];
const band = inputs[2];
const filepath = inputs[3];

logger.debug('Checking GeoServer connectivity …')
const gsExists = await grc.about.exists();
Expand All @@ -60,31 +54,15 @@ const geoServerCreateAndApplySld = async (workerJob, inputs) => {
}
}

let pgClient;
let locations = [];
try {
pgClient = new Client({
host: pghost,
port: pgport,
database: pgdb,
user: pguser,
password: pgpasswd,
});
await pgClient.connect();

const sqlQuery = `SELECT location FROM "${dbTable}"`;
const res = await pgClient.query(sqlQuery);

locations = res.rows.map(row => row.location);
locations = fs.readdirSync(`${filepath}/${sldWorkspace}/${sldWorkspace}_temperature/`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostlikely this needs to be replaces with a fetch()


logger.debug("Locations found for coveragestore: " + locations);
} catch (e) {
logger.error(e);
throw 'SQL execution aborted: ' + e;
} finally {
if (pgClient) {
await pgClient.end();
}
}
throw 'Could not find COG Files: ' + e;
}

let min = 0;
let max = 0;
Expand Down
Loading