forked from DebaucheryLibrarian/traxxx
Added more loggers to http module.
This commit is contained in:
@@ -306,6 +306,12 @@ const { argv } = yargs
|
||||
type: 'array',
|
||||
alias: ['delete-movie', 'remove-movies', 'remove-movies'],
|
||||
})
|
||||
.option('request-timeout', {
|
||||
describe: 'Default timeout after which to cancel a HTTP request.',
|
||||
type: 'number',
|
||||
alias: ['timeout'],
|
||||
default: 60000,
|
||||
})
|
||||
.coerce('after', interpretAfter)
|
||||
.coerce('actors-update', interpretAfter);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Promise.config({
|
||||
});
|
||||
|
||||
const defaultOptions = {
|
||||
timeout: 60000,
|
||||
timeout: argv.requestTimeout,
|
||||
encodeJSON: true,
|
||||
headers: {
|
||||
'user-agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1',
|
||||
@@ -77,6 +77,8 @@ function getLimiter(options = {}, url) {
|
||||
});
|
||||
}
|
||||
|
||||
limiters[interval][concurrency].on('queued', () => logger.silly(`Queued ${url}`));
|
||||
|
||||
return limiters[interval][concurrency];
|
||||
}
|
||||
|
||||
@@ -136,6 +138,7 @@ async function finalizeResult(res, options) {
|
||||
function getTimeout(options, url) {
|
||||
return new Promise((resolve, reject, onCancel) => {
|
||||
const timeout = setTimeout(() => {
|
||||
logger.debug(`Canceled timed out request to ${url}`);
|
||||
reject(new Error(`URL ${url} timed out`));
|
||||
}, (options?.timeout || defaultOptions.timeout) + 10000);
|
||||
|
||||
@@ -166,6 +169,8 @@ async function scheduleRequest(method = 'get', url, body, requestOptions = {}) {
|
||||
|
||||
const curatedResult = await finalizeResult(result, options);
|
||||
|
||||
logger.silly(`Response ${curatedResult.status} for ${method.toUpperCase()} ${url}`);
|
||||
|
||||
return curatedResult;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user