From 030e25c02ddbcbc89feccab03b01d535e7ea8ab9 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 10 Jan 2025 17:08:08 +0200 Subject: [PATCH] [beta18 | DONE | CHANGED] beta-properties.file: Updated port property | cache.js: Added the ability to read the port either from environment variables or from the properties file. --- services/cache/mecache/beta-properties.file | 2 +- services/cache/mecache/cache.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/cache/mecache/beta-properties.file b/services/cache/mecache/beta-properties.file index d34c784c..ef3d54a7 100644 --- a/services/cache/mecache/beta-properties.file +++ b/services/cache/mecache/beta-properties.file @@ -1,4 +1,4 @@ -port = 4000 +port = 3100 utilsService = https://beta.explore.openaire.eu/utils-service environment = beta preloadRequests =https://beta.services.openaire.eu/openaire/info/,https://beta.services.openaire.eu/openaire/contexts/,https://beta.services.openaire.eu/usagestats/allmetrics,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:provenanceActions.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:subject_classification_typologies.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:relation_relClass.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:publication_resource.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:dataCite_resource.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:languages.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:access_modes.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:datasource_typologies.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:datasourceCompatibilityLevel.json,https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:countries.json diff --git a/services/cache/mecache/cache.js b/services/cache/mecache/cache.js index ca40b2f3..da5fc5f9 100644 --- a/services/cache/mecache/cache.js +++ b/services/cache/mecache/cache.js @@ -21,6 +21,8 @@ const lruCache = new LRUCache({ max: cacheMaxSize }); const register = new prom.Registry(); prom.collectDefaultMetrics({register: register}); +const port = process.env['PORT'] || properties.get('port'); + const responses = new prom.Counter({ name: 'cache_http_responses_total', help: 'A counter for cache response codes for every API request.', @@ -160,7 +162,7 @@ app.use((req, res) => { res.status(404).send(getResponse(404, "Not Found")); //not found }); -const server = app.listen(properties.get('port'), function () { +const server = app.listen(port, function () { console.log(`Example app listening on port`, server.address().port) //run the timer resetAtMidnight(); @@ -184,14 +186,14 @@ function clearCache() { async function initCache() { try { const requests = await axios.get(properties.get('utilsService') + '/grouped-requests'); - const additionalDataPromises = requests.data.map((url) => axios.get('http://localhost:'+properties.get('port') + '/get?url=' + properties.get('utilsService') + url)); + const additionalDataPromises = requests.data.map((url) => axios.get('http://localhost:'+port + '/get?url=' + properties.get('utilsService') + url)); const additionalDataResponses = await Promise.all(additionalDataPromises); console.log("Cache initialized group queries!") } catch (error) { console.error('Error fetching data: Cache initialize failed', error); } try{ - const additionalDataPromisesPreloadRequests = preloadRequests.map((url) => axios.get('http://localhost:'+properties.get('port') + '/get?url=' + url)); + const additionalDataPromisesPreloadRequests = preloadRequests.map((url) => axios.get('http://localhost:'+port + '/get?url=' + url)); const additionalDataResponsesPreloadRequests = await Promise.all(additionalDataPromisesPreloadRequests); console.log("Cache initialized preload requests!") } catch (error) {