Increase the default timeout for rtm.start to 180 seconds. · slack-ruby/slack-ruby-client@58ac7a1 · GitHub
Skip to content

Commit 58ac7a1

Browse files
committed
Increase the default timeout for rtm.start to 180 seconds.
1 parent a9e7069 commit 58ac7a1

8 files changed

Lines changed: 65 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion

‎README.md‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ logger | Optional `Logger` instance that logs HTTP requests.
176176
timeout | Optional open/read timeout in seconds.
177177
open_timeout | Optional connection open timeout in seconds.
178178

179+
You can also pass request options, including `timeout` and `open_timeout` into individual calls.
180+
181+
```ruby
182+
client.channels_list(request: { timeout: 180 })
183+
```
184+
179185
### RealTime Client
180186

181187
The Real Time Messaging API is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as user.
@@ -266,7 +272,7 @@ token | Slack API token.
266272
websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
267273
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
268274
store_class | Local store class name, default is an in-memory `Slack::RealTime::Stores::Store`.
269-
start_options | Options to pass into `rtm.start`, default is `{}`.
275+
start_options | Options to pass into `rtm.start`, default is `{ request: { timeout: 180 } }`.
270276
logger | Optional `Logger` instance that logs RealTime requests and socket data.
271277

272278
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
@@ -300,12 +306,16 @@ See a fully working example in [examples/hi_real_time_and_web](examples/hi_real_
300306

301307
### Large Team Considerations
302308

303-
For large teams of thousands of members you may also want to increase the default web client timeout, since `rtm.start` downloads a large amount of data.
309+
The `rtm.start` call downloads a large amount of data. For large teams, consider reducing the amount of unnecessary data downloaded with `start_options`. You may also want to increase the default timeout of 180 seconds.
304310

305311
```ruby
306-
Slack::Web::Client.config do |config|
307-
config.timeout = 5
308-
config.open_timeout = 5
312+
Slack::RealTime::Client.config do |config|
313+
# Return timestamp only for latest message object of each channel.
314+
config.start_options[:simple_latest] = true
315+
# Skip unread counts for each channel.
316+
config.start_options[:no_unreads] = true
317+
# Increase request timeout to 6 minutes.
318+
config.start_options[:request][:timeout] = 360
309319
end
310320
```
311321

‎UPGRADING.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
Upgrading Slack-Ruby-Client
22
===========================
33

4+
### Upgrading to >= 0.8.0
5+
6+
The default timeout for `rtm.start` has been increased from 60 to 180 seconds via `Slack::RealTime::Client.config.start_options[:request][:timeout]`. If you're explicitly setting `start_options` in your application, preserve the value by merging settings instead of replacing the entire `start_options` value.
7+
8+
Before:
9+
10+
```ruby
11+
Slack::RealTime::Client.config do |config|
12+
config.start_options = { no_unreads: true }
13+
end
14+
```
15+
16+
After:
17+
18+
```ruby
19+
Slack::RealTime::Client.config do |config|
20+
config.start_options[:no_unreads] = true # keeps config.start_options[:request] intact
21+
end
22+
```
23+
24+
See [#136](https://github.com/slack-ruby/slack-ruby-client/pull/136) for more details.
25+
426
### Upgrading to >= 0.6.0
527

628
#### Changes to API Response Data

‎lib/slack/real_time/config.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def reset
2222
self.websocket_proxy = nil
2323
self.token = nil
2424
self.concurrency = method(:detect_concurrency)
25-
self.start_options = {}
25+
self.start_options = { request: { timeout: 180 } }
2626
self.store_class = Slack::RealTime::Store
2727
self.logger = nil
2828
end

‎lib/slack/web/faraday/request.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def request(method, path, options)
3030
request.path = path
3131
request.body = options unless options.empty?
3232
end
33+
request.options.merge!(options.delete(:request)) if options.key?(:request)
3334
end
3435
response.body
3536
end

‎spec/slack/real_time/client_spec.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
client.start!
207207
end
208208
it 'sets start_options' do
209-
expect(client.start_options).to eq({})
209+
expect(client.start_options).to eq({ request: { timeout: 180 } })
210210
end
211211
end
212212
end

‎spec/slack/web/client_spec.rb‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,26 @@
149149
end
150150
end
151151
end
152+
context 'per-request options' do
153+
it 'applies timeout', vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
154+
# reuse the same connection for the test, otherwise it creates a new one every time
155+
conn = client.send(:connection)
156+
expect(client).to receive(:connection).and_return(conn)
157+
158+
# get the yielded request to reuse in the next call to rtm_start so that we can examine request.options later
159+
request = nil
160+
response = conn.post do |_request|
161+
_request.path = 'rtm.start'
162+
_request.body = { token: 'token' }
163+
request = _request
164+
end
165+
166+
expect(conn).to receive(:post).and_yield(request).and_return(response)
167+
168+
client.rtm_start(request: { timeout: 3 })
169+
170+
expect(request.options.timeout).to eq 3
171+
end
172+
end
152173
end
153174
end

‎spec/support/vcr.rb‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)