Implement retry mechanism (#187)
* Implement retry mechanism * Set retry count to 3 * web app cache key * Changelog
This commit is contained in:
1 parent
4233f30dec
commit
8f59e3648e
6 files changed
+111
-28
No files matched your search
@@ -88,7 +88,7 @@ namespace Invidious
|
||||
url = `${authToken.instance}${Invidious.HISTORY_ENDPOINT}/${videoId}`
|
||||
request = HttpClient.Post(url, "")
|
||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||
request.SendAndForget()
|
||||
request.Send()
|
||||
end function
|
||||
|
||||
function SearchSuggestions(q as string, cancellation = invalid as object) as object
|
||||
@@ -149,6 +149,7 @@ namespace Invidious
|
||||
request.QueryParams(m.DefaultQueryParams())
|
||||
request.Cancellation(cancellation)
|
||||
request.CacheSeconds(60 * 60 * 24)' 24 hours
|
||||
request.TryCount(3)
|
||||
|
||||
return request.Await()
|
||||
end function
|
||||
@@ -250,6 +251,12 @@ namespace Invidious
|
||||
request.CacheSeconds(endpoint.cacheSeconds)
|
||||
end if
|
||||
|
||||
if feedSource.tryCount <> invalid
|
||||
request.TryCount(feedSource.tryCount)
|
||||
else if endpoint.tryCount <> invalid
|
||||
request.TryCount(endpoint.tryCount)
|
||||
end if
|
||||
|
||||
if feedSource.queryParams <> invalid
|
||||
request.QueryParams(feedSource.queryParams)
|
||||
end if
|
||||
@@ -475,7 +482,7 @@ namespace Invidious
|
||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||
request.Header("Content-Type", "application/json")
|
||||
|
||||
request.SendAndForget()
|
||||
request.Send()
|
||||
end function
|
||||
|
||||
function GetAuthorizeTokenLink() as dynamic
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace SponsorBlock
|
||||
end if
|
||||
|
||||
url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.VIEWED_SEGMENT_ENDPOINT}?UUID=${segmentId}`
|
||||
HttpClient.Post(url, "").SendAndForget()
|
||||
HttpClient.Post(url, "").Send()
|
||||
end function
|
||||
|
||||
function GenerateProgressBarBackground(segments as object, lengthSeconds as integer, path as string)
|
||||
|
||||
@@ -142,6 +142,7 @@ channel_info:
|
||||
url: /api/v1/channels/{ucid}
|
||||
responseHandler: ChannelInfoHandler
|
||||
cacheSeconds: 259200 # 3 days
|
||||
tryCount: 3
|
||||
|
||||
# Channel endpoints
|
||||
channel_videos:
|
||||
@@ -149,6 +150,7 @@ channel_videos:
|
||||
url: /api/v1/channels/{ucid}/videos
|
||||
responseHandler: ChannelVideosHandler
|
||||
paginationType: Continuation
|
||||
tryCount: 3
|
||||
queryParams:
|
||||
sort_by:
|
||||
# defaults to newest
|
||||
@@ -162,6 +164,7 @@ channel_playlists:
|
||||
url: /api/v1/channels/{ucid}/playlists
|
||||
responseHandler: ChannelPlaylistsHandler
|
||||
paginationType: Continuation
|
||||
tryCount: 3
|
||||
queryParams:
|
||||
sort_by:
|
||||
required: false
|
||||
@@ -175,21 +178,25 @@ channel_shorts:
|
||||
url: /api/v1/channels/{ucid}/shorts
|
||||
responseHandler: ChannelVideosHandler
|
||||
paginationType: Continuation
|
||||
tryCount: 3
|
||||
|
||||
channel_streams:
|
||||
title: Channel streams
|
||||
url: /api/v1/channels/{ucid}/streams
|
||||
responseHandler: ChannelVideosHandler
|
||||
paginationType: Continuation
|
||||
tryCount: 3
|
||||
|
||||
channel_podcasts:
|
||||
title: Channel podcasts
|
||||
url: /api/v1/channels/{ucid}/podcasts
|
||||
responseHandler: ChannelPlaylistsHandler
|
||||
paginationType: Continuation
|
||||
tryCount: 3
|
||||
|
||||
channel_channels:
|
||||
title: Related channels
|
||||
url: /api/v1/channels/{ucid}/channels
|
||||
responseHandler: ChannelRelatedChannelsHandler
|
||||
paginationType: Continuation
|
||||
tryCount: 3
|
||||
@@ -46,6 +46,7 @@ namespace HttpClient
|
||||
|
||||
function new()
|
||||
m._timeoutSeconds = 30
|
||||
m._tryCount = 1
|
||||
end function
|
||||
|
||||
function Method(method as string) as HttpRequest
|
||||
@@ -141,6 +142,14 @@ namespace HttpClient
|
||||
return m
|
||||
end function
|
||||
|
||||
function TryCount(tryCount as integer) as HttpRequest
|
||||
m._tryCount = ValidInt(tryCount)
|
||||
if m._tryCount < 1
|
||||
m._tryCount = 1
|
||||
end if
|
||||
return m
|
||||
end function
|
||||
|
||||
function NoCache() as HttpRequest
|
||||
m._noCache = true
|
||||
return m
|
||||
@@ -179,14 +188,6 @@ namespace HttpClient
|
||||
end function
|
||||
|
||||
function Send() as HttpRequest
|
||||
return m.DoSend(false)
|
||||
end function
|
||||
|
||||
function SendAndForget() as HttpRequest
|
||||
return m.DoSend(true)
|
||||
end function
|
||||
|
||||
private function DoSend(forget as boolean) as HttpRequest
|
||||
if m.urlTransfer <> invalid or m._cache <> invalid
|
||||
return m
|
||||
end if
|
||||
@@ -215,9 +216,7 @@ namespace HttpClient
|
||||
m.urlTransfer.SetHeaders(m._headers)
|
||||
end if
|
||||
|
||||
if not forget
|
||||
m.urlTransfer.SetMessagePort(CreateObject("roMessagePort"))
|
||||
end if
|
||||
m.urlTransfer.SetMessagePort(CreateObject("roMessagePort"))
|
||||
|
||||
LogInfo("Sending", m._method, m.urlTransfer.GetURL(), "ID:", m.urlTransfer.GetIdentity())
|
||||
|
||||
@@ -268,6 +267,36 @@ namespace HttpClient
|
||||
end function
|
||||
|
||||
function Await() as HttpResponse
|
||||
tryCount = m._tryCount
|
||||
response = invalid
|
||||
|
||||
response = m.AwaitInternal()
|
||||
if response.IsSuccess() or response.TimedOut() or response.IsCancelled() or response.StatusCode() < 500
|
||||
return response
|
||||
end if
|
||||
tryCount -= 1
|
||||
|
||||
while tryCount > 0
|
||||
backoffMs = 1000 + Rnd(2000)
|
||||
LogInfo("Request failed with status code:", response.StatusCode(), "ID:", m.urlTransfer.GetIdentity(), `\nRetrying:`, m._tryCount - tryCount, "in", backoffMs, "ms")
|
||||
|
||||
m.urlTransfer = invalid
|
||||
m._cache = invalid
|
||||
m._sent = invalid
|
||||
|
||||
sleep(backoffMs)
|
||||
|
||||
response = m.AwaitInternal()
|
||||
if response.IsSuccess() or response.TimedOut() or response.IsCancelled() or response.StatusCode() < 500
|
||||
return response
|
||||
end if
|
||||
tryCount -= 1
|
||||
end while
|
||||
|
||||
return response
|
||||
end function
|
||||
|
||||
private function AwaitInternal() as HttpResponse
|
||||
if m.urlTransfer = invalid and m._cache = invalid
|
||||
m.Send()
|
||||
end if
|
||||
|
||||
Reference in new issue
Block a user