Add timeout to requests

This commit is contained in:
Chocobozzz 2020-11-03 09:06:33 +01:00
parent 217666c707
commit d13fd18641
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 8 additions and 2 deletions

View File

@ -21,7 +21,9 @@ async function doRequestWithRetries<T> (
msToWait: number,
currentRetry = 0
): Promise<{ response: request.RequestResponse, body: T }> {
const res = await doRequest<T>(requestOptions)
const updatedRequestOptions = Object.assign({}, requestOptions, { timeout: 10000 })
const res = await doRequest<T>(updatedRequestOptions)
if (res.response.statusCode === 429) {
if (currentRetry < maxRetries) {

View File

@ -102,14 +102,18 @@ export class VideosIndexer extends AbstractScheduler {
logger.info('Adding video data from %s.', host)
do {
logger.debug('Getting results from %s (from = %d).', host, start)
videos = await getVideos(host, start)
start += videos.length
logger.debug('Getting %d results from %s (from = %d).', videos.length, host, start)
logger.debug('Got %d results from %s (from = %d).', videos.length, host, start)
if (videos.length !== 0) {
const { created } = await indexVideos(videos)
logger.debug('Indexed %d videos from %s.', videos.length, host)
// Fetch complete video foreach created video (to get tags)
for (const c of created) {
this.scheduleVideoIndexation(host, c.uuid)