Skip to content

Commit e621e2d

Browse files
authored
feat: connection pooling and idle timeout (#136)
1 parent c72d4ac commit e621e2d

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@ name: build
22

33
on: [pull_request]
44

5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.head_ref }}
7+
cancel-in-progress: true
8+
59
jobs:
610
build:
711
runs-on: ubuntu-latest
812
strategy:
13+
max-parallel: 1
914
matrix:
10-
ruby: ['2.5', '2.6', '2.7', '3.0']
15+
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1']
1116
name: Ruby ${{ matrix.ruby }}
1217
steps:
1318
- uses: actions/checkout@v2
14-
- uses: actions/setup-ruby@v1
19+
- uses: ruby/setup-ruby@v1
1520
with:
1621
ruby-version: ${{ matrix.ruby }}
22+
bundler-cache: true
1723

1824
- env:
1925
STREAM_API_KEY: ${{ secrets.STREAM_API_KEY }}
2026
STREAM_API_SECRET: ${{ secrets.STREAM_API_SECRET }}
2127
run: |
22-
gem install bundler
23-
bundle install --jobs 4 --retry 3
2428
bundle exec rake rubocop
2529
bundle exec rake test

.rubocop.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ Metrics/PerceivedComplexity:
3232
Naming/AccessorMethodName:
3333
Enabled: false
3434

35-
Security/Open:
36-
Enabled: false
37-
3835
Style/AccessorGrouping:
3936
Enabled: false
4037
Style/Documentation:
@@ -43,3 +40,6 @@ Style/DoubleCopDisableDirective:
4340
Enabled: false
4441
Style/FrozenStringLiteralComment:
4542
Enabled: false
43+
44+
Gemspec/RequireMFA:
45+
Enabled: false

lib/stream/client.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'faraday'
2+
require 'faraday/net_http_persistent'
23
require 'stream/errors'
34
require 'stream/feed'
45
require 'stream/signer'
@@ -170,7 +171,10 @@ def initialize(url_generator)
170171
faraday.use RaiseHttpException
171172
faraday.options[:open_timeout] = @options[:default_timeout]
172173
faraday.options[:timeout] = @options[:default_timeout]
173-
faraday.adapter Faraday.default_adapter
174+
faraday.adapter :net_http_persistent, pool_size: 5 do |http|
175+
# AWS load balancer idle timeout is 60 secs, so let's make it 59
176+
http.idle_timeout = 59
177+
end
174178
end
175179
@base_path = url_generator.base_path
176180
@conn.path_prefix = base_path

spec/integration_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
end
88

99
describe 'Integration tests' do
10-
before do
10+
before(:all) do
1111
@client = Stream::Client.new(ENV['STREAM_API_KEY'], ENV['STREAM_API_SECRET'], nil, location: ENV['STREAM_REGION'], default_timeout: 10)
1212
@feed42 = @client.feed('flat', generate_uniq_feed_name)
1313
@feed43 = @client.feed('flat', generate_uniq_feed_name)
@@ -530,6 +530,7 @@
530530
'data' => {
531531
'hobbies' => %w[playing sleeping eating]
532532
},
533+
'id' => 'aabbcc',
533534
'name' => 'juniper'
534535
}
535536
},
@@ -541,6 +542,7 @@
541542
'data' => {
542543
'interests' => ['sunbeams', 'surprise attacks']
543544
},
545+
'id' => 'ddeeff',
544546
'name' => 'ruby'
545547
}
546548
}
@@ -568,6 +570,7 @@
568570
'data' => {
569571
'interests' => ['sunbeams', 'surprise attacks']
570572
},
573+
'id' => 'ddeeff',
571574
'name' => 'ruby'
572575
}
573576
}

stream.gemspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ Gem::Specification.new do |gem|
1414
gem.files = Dir['lib/**/*']
1515
gem.license = 'BSD-3-Clause'
1616
gem.required_ruby_version = '>=2.5.0'
17+
gem.metadata = {
18+
'homepage_uri' => 'https://getstream.io/activity-feeds/',
19+
'bug_tracker_uri' => 'https://github.com/GetStream/stream-ruby/issues',
20+
'documentation_uri' => 'https://getstream.io/activity-feeds/docs/ruby/?language=ruby',
21+
'changelog_uri' => 'https://github.com/GetStream/stream-ruby/blob/main/CHANGELOG.md',
22+
'source_code_uri' => 'https://github.com/GetStream/stream-ruby'
23+
}
24+
1725
gem.add_dependency 'faraday'
26+
gem.add_dependency 'faraday-net_http_persistent'
1827
gem.add_dependency 'jwt'
28+
gem.add_dependency 'net-http-persistent'
1929
gem.add_development_dependency 'rake'
2030
gem.add_development_dependency 'rspec'
2131
gem.add_development_dependency 'simplecov'

0 commit comments

Comments
 (0)