improve fetch pattern

This commit is contained in:
deityhub 2022-01-10 09:00:29 +01:00
parent 0ea2c2a233
commit 6fd81d0bb2
4 changed files with 8 additions and 4 deletions

View File

@ -2,4 +2,6 @@ CLUSTER_KEY=f414c23b4cdf4e84a6a66ecfd528eff2
PROBE_NAME=US
PROBE_KEY=33b674ca-9fdd-11e9-a2a3-2a2ae2dbccez
SERVER_URL=http://localhost:3002
DATA_INGESTOR_URL=http://localhost:3200
DATA_INGESTOR_URL=http://localhost:3200
RESOURCES_LIMIT=10
FETCH_RESOURCES_URL=http://localhost:3400

View File

@ -41,12 +41,12 @@ const _this = {
});
},
getApi: url => {
getApi: (url, limit = 10) => {
const headers = _this.getHeaders();
return new Promise((resolve, reject) => {
axios({
method: 'GET',
url: `${config.dataIngestorUrl}/${url}`,
url: `${config.fetchResourcesUrl}/${url}?limit=${limit}`,
headers,
})
.then(function(response) {

View File

@ -44,4 +44,5 @@ module.exports = {
clusterKey: process.env['CLUSTER_KEY'],
probeVersion: packageJson.version,
dataIngestorUrl: process.env['DATA_INGESTOR_URL'],
fetchResourcesUrl: process.env['FETCH_RESOURCES_URL'],
};

View File

@ -11,6 +11,7 @@ const ServerMonitors = require('./serverMonitors');
const ErrorService = require('../utils/errorService');
const IncomingHttpRequestMonitors = require('./incomingHttpRequestMonitors');
const KubernetesMonitors = require('./kubernetesMonitors');
const limit = process.env.RESOURCES_LIMIT;
// const ApiService = require('../utils/apiService');
/**
@ -28,7 +29,7 @@ const KubernetesMonitors = require('./kubernetesMonitors');
module.exports = {
runJob: async function(monitorStore) {
try {
let monitors = await getApi('probe/monitors');
let monitors = await getApi('probe/monitors', limit);
monitors = JSON.parse(monitors.data); // parse the stringified data
// add monitor to store