Skip stalled requests

This commit is contained in:
freearhey 2021-05-07 16:17:37 +03:00
parent 8f0c9d9919
commit c37a56c8ea

View File

@ -83,9 +83,16 @@ async function checkStatus(playlist) {
console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`) console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`)
} }
} else { } else {
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const timeout = setTimeout(() => {
source.cancel()
}, config.timeout)
await instance await instance
.get(channel.url) .get(channel.url, { cancelToken: source.token })
.then(() => { .then(() => {
clearTimeout(timeout)
results.push(channel) results.push(channel)
if (config.debug) { if (config.debug) {
console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`) console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`)
@ -93,6 +100,7 @@ async function checkStatus(playlist) {
}) })
.then(utils.sleep(config.delay)) .then(utils.sleep(config.delay))
.catch(err => { .catch(err => {
clearTimeout(timeout)
if (err.response && err.response.status === 404) { if (err.response && err.response.status === 404) {
//console.error(err) //console.error(err)
if (config.debug) { if (config.debug) {