Improve handling of request timeout

This commit is contained in:
Yarmo Mackenbach 2021-04-15 22:30:11 +02:00
parent be258abf93
commit 2bf92ff9df
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
7 changed files with 28 additions and 14 deletions

View file

@ -15,12 +15,14 @@ limitations under the License.
*/
const dns = require('dns')
module.exports = async (data, opts) => {
module.exports.timeout = 5000
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
5000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})

View file

@ -16,12 +16,14 @@ limitations under the License.
const bent = require('bent')
const req = bent('GET')
module.exports = async (data, opts) => {
module.exports.timeout = 5000
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
5000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})

View file

@ -17,12 +17,14 @@ const bent = require('bent')
const req = bent('GET')
const E = require('../enums')
module.exports = async (data, opts) => {
module.exports.timeout = 5000
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
5000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})

View file

@ -16,12 +16,14 @@ limitations under the License.
const irc = require('irc-upd')
const validator = require('validator')
module.exports = async (data, opts) => {
module.exports.timeout = 20000
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
20000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})

View file

@ -17,12 +17,14 @@ const bent = require('bent')
const bentReq = bent('GET')
const validator = require('validator')
module.exports = async (data, opts) => {
module.exports.timeout = 5000
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
5000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})

View file

@ -17,12 +17,14 @@ const bent = require('bent')
const bentReq = bent('GET')
const validator = require('validator')
module.exports = async (data, opts) => {
module.exports.timeout = 5000
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
5000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})

View file

@ -18,6 +18,8 @@ const { client, xml } = require('@xmpp/client')
const debug = require('@xmpp/debug')
const validator = require('validator')
module.exports.timeout = 5000
let xmpp = null,
iqCaller = null
@ -43,12 +45,12 @@ const xmppStart = async (service, username, password) => {
})
}
module.exports = async (data, opts) => {
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
5000
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})