Mercurial > rsstweet
comparison 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 |
comparison
equal
deleted
inserted
replaced
218:c5a101bc4a09 | 219:17461f7682a2 |
---|---|
77 | 77 |
78 @user | 78 @user |
79 end | 79 end |
80 | 80 |
81 def client | 81 def client |
82 @clients[client_config_id] ||= Twitter::REST::Client.new(self.class.client_options client_config_id) | 82 Clients.instance.get client_config_id |
83 end | 83 end |
84 | 84 |
85 def client_try(method, *args) | 85 def client_try(method, *args) |
86 initial_config_id = client_config_id | 86 initial_config_id = client_config_id |
87 | 87 |
88 begin | 88 begin |
89 data = client.public_send method, *args | 89 data = client.public_send method, *args |
90 rescue Twitter::Error::TooManyRequests | 90 rescue Twitter::Error::TooManyRequests |
91 @client_config_id += 1 | 91 @client_config_id = (1 + @client_config_id) % @client_config_count |
92 | 92 |
93 if initial_config_id == client_config_id | 93 if initial_config_id == client_config_id |
94 raise | 94 raise |
95 else | 95 else |
96 retry | 96 retry |
104 | 104 |
105 def client_config_id | 105 def client_config_id |
106 @client_config_count ||= $cfg[:twitter].size | 106 @client_config_count ||= $cfg[:twitter].size |
107 @client_config_id ||= rand(@client_config_count) | 107 @client_config_id ||= rand(@client_config_count) |
108 | 108 |
109 @client_config_id %= @client_config_count | 109 @client_config_id |
110 end | 110 end |
111 end | 111 end |