diff app/models/tweet.rb @ 219:17461f7682a2

One client for everyone
author nanaya <me@nanaya.pro>
date Thu, 27 May 2021 02:28:18 +0900
parents 3176bd0d3c2c
children 0e15b4db2da8
line wrap: on
line diff
--- a/app/models/tweet.rb	Thu May 27 01:53:53 2021 +0900
+++ b/app/models/tweet.rb	Thu May 27 02:28:18 2021 +0900
@@ -79,7 +79,7 @@
   end
 
   def client
-    @clients[client_config_id] ||= Twitter::REST::Client.new(self.class.client_options client_config_id)
+    Clients.instance.get client_config_id
   end
 
   def client_try(method, *args)
@@ -88,7 +88,7 @@
     begin
       data = client.public_send method, *args
     rescue Twitter::Error::TooManyRequests
-      @client_config_id += 1
+      @client_config_id = (1 + @client_config_id) % @client_config_count
 
       if initial_config_id == client_config_id
         raise
@@ -106,6 +106,6 @@
     @client_config_count ||= $cfg[:twitter].size
     @client_config_id ||= rand(@client_config_count)
 
-    @client_config_id %= @client_config_count
+    @client_config_id
   end
 end