diff 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
line wrap: on
line diff
--- a/app/models/tweet.rb	Tue Oct 02 23:58:36 2018 +0900
+++ b/app/models/tweet.rb	Thu Oct 04 22:21:57 2018 +0900
@@ -10,6 +10,16 @@
     (15 + rand(15)).minutes
   end
 
+  def self.client_options(id)
+    {
+      :timeouts => {
+        :connect => 5,
+        :read => 5,
+        :write => 5,
+      },
+    }.merge $cfg[:twitter][id]
+  end
+
   def initialize(twitter_id)
     @clients = {}
     @twitter_id = twitter_id
@@ -69,12 +79,7 @@
   end
 
   def client
-    @clients[client_config_id] ||=
-      Twitter::REST::Client.new do |config|
-        $cfg[:twitter][client_config_id].each do |cfg_key, cfg_value|
-          config.public_send(:"#{cfg_key}=", cfg_value)
-        end
-      end
+    @clients[client_config_id] ||= Twitter::REST::Client.new(self.class.client_options client_config_id)
   end
 
   def client_try(method, *args)