comparison app/models/tweet.rb @ 176:08cc4a4d8a5f

Timeout and simpler client config
author nanaya <me@nanaya.pro>
date Thu, 04 Oct 2018 22:21:57 +0900
parents 5af9b537db86
children 3176bd0d3c2c
comparison
equal deleted inserted replaced
175:52252ae4b580 176:08cc4a4d8a5f
6 :tweet_mode => :extended, 6 :tweet_mode => :extended,
7 } 7 }
8 8
9 def self.cache_expires_time 9 def self.cache_expires_time
10 (15 + rand(15)).minutes 10 (15 + rand(15)).minutes
11 end
12
13 def self.client_options(id)
14 {
15 :timeouts => {
16 :connect => 5,
17 :read => 5,
18 :write => 5,
19 },
20 }.merge $cfg[:twitter][id]
11 end 21 end
12 22
13 def initialize(twitter_id) 23 def initialize(twitter_id)
14 @clients = {} 24 @clients = {}
15 @twitter_id = twitter_id 25 @twitter_id = twitter_id
67 77
68 @user 78 @user
69 end 79 end
70 80
71 def client 81 def client
72 @clients[client_config_id] ||= 82 @clients[client_config_id] ||= Twitter::REST::Client.new(self.class.client_options client_config_id)
73 Twitter::REST::Client.new do |config|
74 $cfg[:twitter][client_config_id].each do |cfg_key, cfg_value|
75 config.public_send(:"#{cfg_key}=", cfg_value)
76 end
77 end
78 end 83 end
79 84
80 def client_try(method, *args) 85 def client_try(method, *args)
81 initial_config_id = client_config_id 86 initial_config_id = client_config_id
82 87