comparison app/models/tweet.rb @ 134:3646b3e319c7

Only try/catch the tweet downloading part
author nanaya <me@nanaya.pro>
date Wed, 13 Dec 2017 02:28:34 +0900
parents 8b2d770160e3
children 3fc882b0884d
comparison
equal deleted inserted replaced
133:64f697fe3af1 134:3646b3e319c7
4 end 4 end
5 5
6 def timeline 6 def timeline
7 start_client_config_id = @client_config_id 7 start_client_config_id = @client_config_id
8 8
9 begin 9 @timeline ||=
10 @timeline ||= 10 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => cache_expires_time) do
11 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => cache_expires_time) do 11 begin
12 @client.user_timeline(@twitter_id, :count => 100, :exclude_replies => false, :include_rts => true, :tweet_mode => :extended) 12 @client.user_timeline(@twitter_id, :count => 100, :exclude_replies => false, :include_rts => true, :tweet_mode => :extended)
13 rescue Twitter::Error::TooManyRequests
14 next_client_config_id = @client_config_id + 1
15 init_client next_client_config_id
16
17 if @client_config_id == start_client_config_id
18 raise
19 else
20 retry
21 end
13 end 22 end
14 rescue Twitter::Error::TooManyRequests
15 next_client_config_id = @client_config_id + 1
16 init_client next_client_config_id
17
18 if @client_config_id == start_client_config_id
19 raise
20 else
21 retry
22 end 23 end
23 end
24 end 24 end
25 25
26 def user 26 def user
27 @user ||= 27 @user ||=
28 if timeline.any? 28 if timeline.any?