Skip to content

Commit b10b6e6

Browse files
committed
[deploy] 스크래핑 안될때 페이지 전체 로드 안된건 막기
1 parent 695ea5a commit b10b6e6

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

moodico/recommendation/views.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ def get_recommendation_list(force_refresh=False):
3838
cached = cache.get(CACHE_KEY)
3939
# 캐시가 없거나 force_refresh(자발적인 refresh)이면
4040
if (not cached) or force_refresh:
41-
raw_data = scrape_oliveyoung_products()
42-
search_results = make_search_results(raw_data)
43-
payload = {
44-
"results": search_results,
45-
"fetched_at": int(time.time()), # 언제 refresh 됐는지 알 수 있게
46-
}
47-
cache.set(CACHE_KEY, payload, CACHE_TTL)
48-
return payload
41+
try:
42+
raw_data = scrape_oliveyoung_products()
43+
search_results = make_search_results(raw_data)
44+
payload = {
45+
"results": search_results,
46+
"fetched_at": int(time.time()), # 언제 refresh 됐는지 알 수 있게
47+
}
48+
cache.set(CACHE_KEY, payload, CACHE_TTL)
49+
return payload
50+
except Exception as e:
51+
if cached:
52+
return cached
53+
return {"results": [], "fetched_at": None} # prevent 500
4954

5055
return cached
5156

0 commit comments

Comments
 (0)