flying-sphinx 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f6ae3a86fa09f28adfe144f1e33ebc0cbd16e612146f77dd14634616a9de420
4
- data.tar.gz: b7945e84452327eac48a975da634cb196d619c602a16233d7fe9f58f0aeb31a6
3
+ metadata.gz: 32b8175efa0d0846873f557091c82fc88f3618840a176b4e04af8e913c52b2b3
4
+ data.tar.gz: d0e1bc6ba2684eb8785ded846e92e2946ce3fe2dd8e42386a54551d8433810e9
5
5
  SHA512:
6
- metadata.gz: 4aa2d490c2d47ba961ad9c8cc5eb6b98c88df1ebbe12f20fcec691cfa02ebb2b87bdccfdee1121c2956b19c97239c3e1f228b1d90e6480db8d7ccdc5b09af18b
7
- data.tar.gz: 91e86268a161e4d3fb1505132f982b09fa5114e567bfdfabed01f2a3f2b25b6364e975a601e8eb588e772ead7cdc3b9b29e398964a3f0ab211e446020121e995
6
+ metadata.gz: dac4e7aec527cda3258d06ac3fb8cb3eb959ccf3f87af9f0c1b6241dd5f3c8293932163dba66740eee54e748d7842622d49742352d706d8405fec4f269251d2e
7
+ data.tar.gz: 99c512ceac2d85230f6d144c1154d77ade553ca3de54de354e899d441c50706cce981bde3cc1e4ca4b398f237276f1f139ff4a71e1ab3f544393cce585357b3c
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-20.04
8
+
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: [ '2.6', '2.7', '3.0', '3.1' ]
13
+ rails: [ '5.0', '5.1', '5.2', '6.0', '6.1', '7.0' ]
14
+ exclude:
15
+ - ruby: '2.6'
16
+ rails: '7.0'
17
+ - ruby: '2.7'
18
+ rails: '7.0'
19
+ - ruby: '3.0'
20
+ rails: '5.0'
21
+ - ruby: '3.0'
22
+ rails: '5.1'
23
+ - ruby: '3.0'
24
+ rails: '5.2'
25
+ - ruby: '3.1'
26
+ rails: '5.0'
27
+ - ruby: '3.1'
28
+ rails: '5.1'
29
+ - ruby: '3.1'
30
+ rails: '5.2'
31
+ - ruby: '3.1'
32
+ rails: '6.0'
33
+
34
+ steps:
35
+ - name: Check out code
36
+ uses: actions/checkout@v2
37
+ - name: Set up ruby
38
+ uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: ${{ matrix.ruby }}
41
+ bundler-cache: true
42
+ - name: Set up Appraisal
43
+ run: bundle exec appraisal generate
44
+ - name: Install gems
45
+ env:
46
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile"
47
+ run: bundle update
48
+ - name: Test
49
+ env:
50
+ CI: "true"
51
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile"
52
+ run: bundle exec rspec
data/Appraisals CHANGED
@@ -1,33 +1,23 @@
1
- appraise 'rails-3.2' do
2
- gem 'rails', '~> 3.2.18'
3
- gem 'faraday', '~> 0.8.0'
4
- end if RUBY_VERSION.to_f <= 2.3
5
-
6
- appraise 'rails-4.0' do
7
- gem 'rails', '~> 4.0.5'
8
- gem 'faraday', '~> 0.9.0'
9
- end if RUBY_VERSION.to_f <= 2.3
10
-
11
- appraise 'rails-4.1' do
12
- gem 'rails', '~> 4.1.16'
13
- end if RUBY_VERSION.to_f <= 2.3
14
-
15
- appraise 'rails-4.2' do
16
- gem 'rails', '~> 4.2.10'
17
- end if RUBY_VERSION.to_f <= 2.3
18
-
19
- appraise 'rails-5.0' do
1
+ appraise 'rails_5.0' do
20
2
  gem 'rails', '~> 5.0.6'
21
- end
3
+ end if RUBY_VERSION.to_f <= 2.7
22
4
 
23
- appraise 'rails-5.1' do
5
+ appraise 'rails_5.1' do
24
6
  gem 'rails', '~> 5.1.4'
25
- end
7
+ end if RUBY_VERSION.to_f <= 2.7
26
8
 
27
- appraise 'rails-5.2' do
9
+ appraise 'rails_5.2' do
28
10
  gem 'rails', '~> 5.2.0'
11
+ end if RUBY_VERSION.to_f <= 2.7
12
+
13
+ appraise 'rails_6.0' do
14
+ gem 'rails', '~> 6.0.0'
15
+ end if RUBY_VERSION.to_f <= 3.0
16
+
17
+ appraise 'rails_6.1' do
18
+ gem 'rails', '~> 6.1.0'
29
19
  end
30
20
 
31
- appraise 'rails_6_0' do
32
- gem 'rails', '~> 6.0.0.beta2'
33
- end if RUBY_VERSION.to_f >= 2.5
21
+ appraise 'rails_7.0' do
22
+ gem 'rails', '~> 7.0.0'
23
+ end if RUBY_VERSION.to_f >= 2.7
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project (at least, from v0.4.0 onwards) are documented in this file.
4
4
 
5
+ ## 3.0.0 - 2022-04-12
6
+
7
+ ### Changed
8
+
9
+ * Supports (and requires) Faraday v2+.
10
+ * Dropped support for Ruby 2.5 and older.
11
+ * Dropped support for Rails 4.2 and older.
12
+
13
+ No functional changes to the gem beyond the Faraday changes, though the tests and CI have had some improvements.
14
+
5
15
  ## 2.2.0 - 2020-04-04
6
16
 
7
17
  ### Added
@@ -17,19 +17,20 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ['lib']
18
18
  s.executables = ['flying-sphinx']
19
19
 
20
- s.add_runtime_dependency 'ey-hmac', '~> 2.2'
21
- s.add_runtime_dependency 'faraday', '>= 0.7'
22
- s.add_runtime_dependency 'gzipped_tar', '~> 0.1.1'
20
+ s.add_runtime_dependency 'ey-hmac', '~> 2.4'
21
+ s.add_runtime_dependency 'faraday', '>= 2'
22
+ s.add_runtime_dependency 'faraday-multipart'
23
+ s.add_runtime_dependency 'gzipped_tar', '>= 0.1.2'
23
24
  s.add_runtime_dependency 'multi_json', '>= 1.3.0'
24
- s.add_runtime_dependency 'pusher-client', '~> 0.3'
25
+ s.add_runtime_dependency 'pusher-client', '~> 0.6'
25
26
  s.add_runtime_dependency 'thinking-sphinx', '>= 4.0.0'
26
27
 
27
- s.add_development_dependency 'appraisal', '~> 2.2'
28
- s.add_development_dependency 'dotenv', '~> 0.11.1'
29
- s.add_development_dependency 'em-websocket', '~> 0.5.1'
28
+ s.add_development_dependency 'appraisal', '~> 2.4'
29
+ s.add_development_dependency 'dotenv', '~> 2.7'
30
30
  s.add_development_dependency 'mysql2', '>= 0.3.15'
31
31
  s.add_development_dependency 'rack'
32
32
  s.add_development_dependency 'rspec', '~> 2.14'
33
33
  s.add_development_dependency 'rspec-retry', '~> 0.4'
34
- s.add_development_dependency 'webmock', '~> 3.8'
34
+ s.add_development_dependency 'webmock', '~> 3.14'
35
+ s.add_development_dependency 'websocket-driver'
35
36
  end
@@ -1,3 +1,5 @@
1
+ require "faraday/multipart"
2
+
1
3
  class FlyingSphinx::Configurer
2
4
  InvalidVersionError = Class.new FlyingSphinx::Error
3
5
  PresignatureError = Class.new FlyingSphinx::Error
@@ -1,4 +1,4 @@
1
- class FlyingSphinx::Response::Invalid < Faraday::Response::Middleware
1
+ class FlyingSphinx::Response::Invalid < Faraday::Middleware
2
2
  def on_complete(environment)
3
3
  return unless environment[:status] == 403
4
4
 
@@ -1,4 +1,4 @@
1
- class FlyingSphinx::Response::JSON < Faraday::Response::Middleware
1
+ class FlyingSphinx::Response::JSON < Faraday::Middleware
2
2
  def on_complete(environment)
3
3
  return if environment[:request_headers]['Authorization'].nil?
4
4
 
@@ -1,4 +1,4 @@
1
- class FlyingSphinx::Response::Logger < Faraday::Response::Middleware
1
+ class FlyingSphinx::Response::Logger < Faraday::Middleware
2
2
  extend Forwardable
3
3
 
4
4
  def call(environment)
@@ -1,3 +1,3 @@
1
1
  module FlyingSphinx
2
- Version = '2.2.0'
2
+ Version = '3.0.0'
3
3
  end
@@ -17,6 +17,7 @@ describe FlyingSphinx::Action do
17
17
  end
18
18
 
19
19
  def perform_and_complete(action)
20
+ Thread.report_on_exception = false
20
21
  thread = Thread.new { action.perform }
21
22
  sleep 0.01
22
23
  action.send :completion, '{"id":748}'
@@ -83,6 +84,7 @@ describe FlyingSphinx::Action do
83
84
  it "logs a warning when the action fails" do
84
85
  logger.should_receive(:warn).with("Action failed.")
85
86
 
87
+ Thread.report_on_exception = false
86
88
  thread = Thread.new { action.perform }
87
89
  sleep 0.01
88
90
  action.send :failure, '{"id":748}'
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,6 @@ require 'bundler'
3
3
 
4
4
  require 'dotenv'
5
5
  require 'webmock/rspec'
6
- require 'em-websocket'
7
6
  require 'rack'
8
7
 
9
8
  Dotenv.load '.env.test'
@@ -1,48 +1,75 @@
1
+ require "socket"
2
+
1
3
  class LocalPusher
2
4
  attr_reader :connections
3
5
 
4
6
  def initialize
5
- @connections = []
7
+ mutex.synchronize do
8
+ @connections = []
9
+ @alive = true
10
+ end
6
11
  end
7
12
 
8
13
  def start
14
+ Thread.report_on_exception = false
9
15
  @server_thread ||= Thread.new do
10
- EM.run { socket_server }
16
+ socket_server
11
17
  end
12
18
  end
13
19
 
14
20
  def stop
15
- server_thread.kill
21
+ mutex.synchronize do
22
+ connections.each(&:close)
23
+ @alive = false
24
+ end
25
+
26
+ server_thread.join(5)
16
27
  end
17
28
 
18
29
  def send(event, data)
19
- connections.each do |connection|
20
- connection.send({
21
- 'event' => event,
22
- 'data' => data.to_json,
23
- 'channel' => ENV['FLYING_SPHINX_IDENTIFIER']
24
- }.to_json)
30
+ mutex.synchronize do
31
+ connections.each do |connection|
32
+ connection.write_json(
33
+ 'event' => event,
34
+ 'data' => data.to_json,
35
+ 'channel' => ENV['FLYING_SPHINX_IDENTIFIER']
36
+ )
37
+ end
25
38
  end
26
39
  end
27
40
 
28
41
  private
29
42
 
30
- attr_reader :server_thread
43
+ attr_reader :server_thread, :alive
44
+
45
+ def mutex
46
+ @mutex ||= Mutex.new
47
+ end
31
48
 
32
49
  def socket_server
33
- EM::WebSocket.run(
34
- :host => ENV['FLYING_SPHINX_SOCKETS_HOST'],
35
- :port => ENV['FLYING_SPHINX_SOCKETS_PORT']
36
- ) do |connection|
37
- connection.onopen do |handshake|
38
- connections << connection
39
- connection.send({
40
- 'event' => 'pusher:connection_established',
41
- 'data' => {'socket_id' => 101}.to_json
42
- }.to_json)
43
- end
50
+ server = TCPServer.new(
51
+ ENV['FLYING_SPHINX_SOCKETS_HOST'],
52
+ ENV['FLYING_SPHINX_SOCKETS_PORT'].to_i
53
+ )
44
54
 
45
- connection.onclose { connections.delete connection }
55
+ loop do
56
+ break unless mutex.synchronize { alive }
57
+ connection = LocalPusherConnection.new(server.accept_nonblock)
58
+ mutex.synchronize { connections << connection }
59
+
60
+ loop do
61
+ break unless mutex.synchronize { alive }
62
+ connection.parse
63
+ end
64
+ rescue IO::WaitReadable, Errno::EINTR
65
+ IO.select([server])
66
+ retry
46
67
  end
68
+ rescue Errno::EADDRINUSE
69
+ puts "Socket failure, retrying..."
70
+ sleep 1
71
+ retry
72
+ ensure
73
+ server.close
47
74
  end
48
75
  end
@@ -0,0 +1,40 @@
1
+ require "websocket/driver"
2
+
3
+ class LocalPusherConnection
4
+ def initialize(socket)
5
+ @socket = socket
6
+
7
+ driver.on :connect, -> (event) do
8
+ driver.start
9
+ write_json(
10
+ 'event' => 'pusher:connection_established',
11
+ 'data' => {'socket_id' => 101}.to_json
12
+ )
13
+ end
14
+ end
15
+
16
+ def close
17
+ socket.close
18
+ end
19
+
20
+ def parse
21
+ driver.parse(socket.gets)
22
+ rescue IOError
23
+ end
24
+
25
+ def write(string)
26
+ socket.write(string)
27
+ end
28
+
29
+ def write_json(object)
30
+ driver.text(object.to_json)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :socket
36
+
37
+ def driver
38
+ @driver ||= WebSocket::Driver.server(self)
39
+ end
40
+ end
@@ -8,6 +8,7 @@ class SuccessfulAction
8
8
 
9
9
  def matches?(block)
10
10
  pusher.start
11
+ Thread.report_on_exception = false
11
12
  thread = Thread.new { call block }
12
13
  sleep 1.5
13
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flying-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-04 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ey-hmac
@@ -16,42 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
26
+ version: '2.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0.7'
33
+ version: '2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0.7'
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-multipart
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: gzipped_tar
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: 0.1.1
61
+ version: 0.1.2
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: 0.1.1
68
+ version: 0.1.2
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: multi_json
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.3'
89
+ version: '0.6'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.3'
96
+ version: '0.6'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: thinking-sphinx
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -100,42 +114,28 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '2.2'
117
+ version: '2.4'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '2.2'
124
+ version: '2.4'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: dotenv
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: 0.11.1
131
+ version: '2.7'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: 0.11.1
125
- - !ruby/object:Gem::Dependency
126
- name: em-websocket
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.5.1
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 0.5.1
138
+ version: '2.7'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: mysql2
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -198,14 +198,28 @@ dependencies:
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '3.8'
201
+ version: '3.14'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '3.8'
208
+ version: '3.14'
209
+ - !ruby/object:Gem::Dependency
210
+ name: websocket-driver
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
209
223
  description: Hooks Thinking Sphinx into the Flying Sphinx service
210
224
  email: pat@freelancing-gods.com
211
225
  executables:
@@ -215,8 +229,8 @@ extra_rdoc_files:
215
229
  - README.textile
216
230
  files:
217
231
  - ".env.test"
232
+ - ".github/workflows/ci.yml"
218
233
  - ".gitignore"
219
- - ".travis.yml"
220
234
  - Appraisals
221
235
  - CHANGELOG.markdown
222
236
  - Gemfile
@@ -285,12 +299,13 @@ files:
285
299
  - spec/support/command_helpers.rb
286
300
  - spec/support/hmac.rb
287
301
  - spec/support/local_pusher.rb
302
+ - spec/support/local_pusher_connection.rb
288
303
  - spec/support/multipart.rb
289
304
  - spec/support/successful_action.rb
290
305
  homepage: https://flying-sphinx.com
291
306
  licenses: []
292
307
  metadata: {}
293
- post_install_message:
308
+ post_install_message:
294
309
  rdoc_options: []
295
310
  require_paths:
296
311
  - lib
@@ -305,8 +320,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
320
  - !ruby/object:Gem::Version
306
321
  version: '0'
307
322
  requirements: []
308
- rubygems_version: 3.0.3
309
- signing_key:
323
+ rubygems_version: 3.2.32
324
+ signing_key:
310
325
  specification_version: 4
311
326
  summary: Sphinx in the Cloud
312
327
  test_files:
@@ -334,5 +349,6 @@ test_files:
334
349
  - spec/support/command_helpers.rb
335
350
  - spec/support/hmac.rb
336
351
  - spec/support/local_pusher.rb
352
+ - spec/support/local_pusher_connection.rb
337
353
  - spec/support/multipart.rb
338
354
  - spec/support/successful_action.rb
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.8
4
- - 2.4.5
5
- - 2.5.3
6
- - 2.6.1
7
- before_install:
8
- - gem update --system
9
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
10
- - gem install bundler -v '< 2'
11
- before_script:
12
- - bundle exec appraisal install
13
- cache: bundler
14
- script: bundle exec appraisal rspec