Add error handling for top videos

This commit is contained in:
Omar Roth 2018-03-19 12:35:35 -05:00
parent fb87b3347b
commit 48da2ced46
2 changed files with 13 additions and 3 deletions

View File

@ -259,7 +259,12 @@ def rank_videos(db, n, pool, filter)
break
else
client = get_client(pool)
video = get_video(id, client, db)
begin
video = get_video(id, client, db)
rescue ex
next
end
pool << client
if video.language
@ -267,7 +272,7 @@ def rank_videos(db, n, pool, filter)
else
description = XML.parse(video.description)
content = [video.title, description.content].join(" ")
content = content[0,10000]
content = content[0, 10000]
results = DetectLanguage.detect(content)
language = results[0].language

View File

@ -135,7 +135,11 @@ spawn do
end
loop do
top = rank_videos(PG_DB, 40, youtube_pool, filter)
begin
top = rank_videos(PG_DB, 40, youtube_pool, filter)
rescue ex
next
end
if top.size > 0
args = arg_array(top)
@ -150,6 +154,7 @@ spawn do
begin
videos << get_video(id, client, PG_DB)
rescue ex
next
end
youtube_pool << client
end