diff --git a/lib/archive.js b/lib/archive.js index f441806..3fc3aa1 100644 --- a/lib/archive.js +++ b/lib/archive.js @@ -1,5 +1,5 @@ const { logger } = require('@vtfk/logger') -const axios = require('axios').default +const axios = require('./axios-instance')() const { fromBuffer } = require('file-type') const path = require('path') const { ARCHIVE_URL, ARCHIVE_KEY, FILE_FORMATS } = require('../config') @@ -48,11 +48,11 @@ const callArchive = async (payload, e18JobId, e18TaskId, endpoint) => { }, maxBodyLength } - const { data } = await axios.post(`${ARCHIVE_URL}/${endpoint}`, payload, headers) logger('info', ['archive', 'callArchive', 'data found']) return data } catch (error) { + console.log(error.response?.data || error.stack || error.toString()) const { status, message, data } = error.response if ((status === 404 && endpoint === 'SyncElevmappe') || (data && data.error && data.error === 'VANLIG BOSATT, mangler ADR og ADR1-3')) { logger('info', ['archive', 'aiaiaiaiai', status, message || data]) diff --git a/lib/axios-instance.js b/lib/axios-instance.js new file mode 100644 index 0000000..5415563 --- /dev/null +++ b/lib/axios-instance.js @@ -0,0 +1,18 @@ +const axios = require('axios').default +const https = require('https') + +let instance = null + +// To avoid TCP port exhaustion on many runs at once +module.exports = () => { + if (!instance) { + console.log('instance does not exits - creating') + instance = axios.create({ + httpsAgent: new https.Agent({ + keepAlive: true, + maxSockets: 200 + }) + }) + } + return instance +} diff --git a/lib/e18.js b/lib/e18.js index 6788fa0..9578bd4 100644 --- a/lib/e18.js +++ b/lib/e18.js @@ -1,4 +1,4 @@ -const axios = require('axios').default +const axios = require('./axios-instance')() const { logger } = require('@vtfk/logger') const { E18_URL, E18_KEY, E18: { PROJECT_ID: projectId, SYSTEM: system, TYPE: type } } = require('../config') diff --git a/lib/isi-lokal.js b/lib/isi-lokal.js index 658c664..b053d4e 100644 --- a/lib/isi-lokal.js +++ b/lib/isi-lokal.js @@ -1,5 +1,5 @@ const { logger } = require('@vtfk/logger') -const axios = require('axios').default +const axios = require('./axios-instance')() const { parseStringPromise, processors } = require('xml2js') const { ISI: { URL, GET_DOCUMENTS, SET_STATUS } } = require('../config')