mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Gave image request a bit of time to resolve
This commit is contained in:
parent
72826f87fe
commit
cbb1e0b2c2
@ -16,12 +16,14 @@ from threading import Lock
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
import sqlalchemy as sql
|
import sqlalchemy as sql
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MAX_RESOLVE_THREADS = 5
|
MAX_RESOLVE_THREADS = 5
|
||||||
|
MAX_SECONDS_TO_RESOLVE_REQUEST = 5
|
||||||
|
|
||||||
|
|
||||||
# remove old db file (columns missing)
|
# remove old db file (columns missing)
|
||||||
@ -263,6 +265,13 @@ def resolve_image(artist_id=None,track_id=None,album_id=None):
|
|||||||
|
|
||||||
# the actual http request for the full image
|
# the actual http request for the full image
|
||||||
def image_request(artist_id=None,track_id=None,album_id=None):
|
def image_request(artist_id=None,track_id=None,album_id=None):
|
||||||
|
|
||||||
|
# because we use lazyload, we can allow our http requests to take a little while at least
|
||||||
|
# not the full backend request, but a few seconds to give us time to fetch some images
|
||||||
|
# because 503 retry-after doesn't seem to be honored
|
||||||
|
attempt = 0
|
||||||
|
while attempt < MAX_SECONDS_TO_RESOLVE_REQUEST:
|
||||||
|
attempt += 1
|
||||||
# check cache
|
# check cache
|
||||||
result = get_image_from_cache(artist_id=artist_id,track_id=track_id,album_id=album_id)
|
result = get_image_from_cache(artist_id=artist_id,track_id=track_id,album_id=album_id)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
@ -277,7 +286,8 @@ def image_request(artist_id=None,track_id=None,album_id=None):
|
|||||||
if album_id:
|
if album_id:
|
||||||
result['value'] = placeholder_url + f"joy-division&colors={album_id % 100}"
|
result['value'] = placeholder_url + f"joy-division&colors={album_id % 100}"
|
||||||
return result
|
return result
|
||||||
else:
|
time.sleep(1)
|
||||||
|
|
||||||
# no entry, which means we're still working on it
|
# no entry, which means we're still working on it
|
||||||
return {'type':'noimage','value':'wait'}
|
return {'type':'noimage','value':'wait'}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user