faye-reconnect 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +4 -4
- data/faye-reconnect.gemspec +6 -6
- data/lib/faye/reconnect/client_extension.rb +15 -1
- data/lib/faye/reconnect/version.rb +1 -1
- data/spec/client_extension_spec.rb +7 -1
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '09c9aa50ab9b10bc3ab23fc21f523785772429819b0730c868640a23bc883c03'
|
4
|
+
data.tar.gz: 9800a0e214785d34fc1b522ba850d523e4586e593835058de40f4aa5a9e41873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 280ef8208c7155290d49f916fbd3ee34d935ee666a71b4b00c4590b47d9bd56a8de06f1539f97d11cbeef0b7b22bdd98a0727fd6a396d1f8d7cfe44a6df5d0a6
|
7
|
+
data.tar.gz: 8fd10daa1ffdb2d2a699845aa7859157c11cffea6a68b1410a62d6b8a6ccfa613cdb03c124ffee2873282797df6575ad8c78f1a77be4fbc232e9811c7878e972
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ server.add_extension Faye::Reconnect::ServerExtension.new(server)
|
|
39
39
|
|
40
40
|
### Client Side
|
41
41
|
|
42
|
-
The client extension has a dependency on redis.
|
42
|
+
The client extension has a dependency on redis.
|
43
43
|
It uses redis to persist the client id after each successful handshake so it can re-use it when trying to reconnect.
|
44
44
|
|
45
45
|
Add the extension to your faye client :
|
@@ -66,7 +66,7 @@ If you don't specify redis options, the ones provided in the above example will
|
|
66
66
|
You may already have something along the lines of :
|
67
67
|
|
68
68
|
```ruby
|
69
|
-
trap('TERM') do
|
69
|
+
trap('TERM') do
|
70
70
|
client.disconnect
|
71
71
|
end
|
72
72
|
```
|
@@ -74,7 +74,7 @@ end
|
|
74
74
|
If you plan on reconnecting with the same client id and get missing messages, you have to use the ``stop!`` method provided by this gem :
|
75
75
|
|
76
76
|
```ruby
|
77
|
-
trap('TERM') do
|
77
|
+
trap('TERM') do
|
78
78
|
client.stop!
|
79
79
|
end
|
80
80
|
```
|
@@ -84,7 +84,7 @@ Instead of sending a ``/meta/disconnect`` message to the server, it will cleanly
|
|
84
84
|
|
85
85
|
## Contributing
|
86
86
|
|
87
|
-
1. Fork it (
|
87
|
+
1. Fork it (https://github.com/jarthod/faye-reconnect/fork)
|
88
88
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
89
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
90
90
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/faye-reconnect.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'faye/reconnect/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "faye-reconnect"
|
8
8
|
spec.version = Faye::Reconnect::VERSION
|
9
|
-
spec.authors = ["Adrien Siami"]
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["Adrien Jarthon", "Adrien Siami"]
|
10
|
+
spec.email = ["jobs@adrienjarthon.com"]
|
11
11
|
spec.summary = "Allow a long running faye client to reconnect to a faye server with the same client ID"
|
12
12
|
spec.description = "Allow a long running faye client to reconnect to a faye server with the same client ID"
|
13
13
|
spec.homepage = ""
|
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'em-hiredis', '~> 0.3'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler'
|
24
|
-
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'rspec-eventmachine'
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'rspec-eventmachine'
|
27
27
|
spec.add_development_dependency 'thin'
|
28
28
|
spec.add_development_dependency 'pry-byebug'
|
29
29
|
|
@@ -4,9 +4,14 @@ module Faye
|
|
4
4
|
module Reconnect
|
5
5
|
class ClientExtension
|
6
6
|
|
7
|
-
def
|
7
|
+
def self.finalize(redis)
|
8
|
+
proc { redis&.close_connection }
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize redis: nil, name:, on_handshake: nil
|
8
12
|
@name = name
|
9
13
|
@clientIdFetched = false
|
14
|
+
@on_handshake = on_handshake
|
10
15
|
redis ||= {}
|
11
16
|
redis[:host] ||= 'localhost'
|
12
17
|
redis[:port] ||= 6379
|
@@ -15,6 +20,8 @@ module Faye
|
|
15
20
|
@redis = EventMachine::Hiredis::Client.new(redis[:host], redis[:port], redis[:password], redis[:database])
|
16
21
|
EM.schedule do
|
17
22
|
@redis.connect
|
23
|
+
@redis.client('setname', "faye-reconnect/#{name}[#{Socket.gethostname}][#{Process.pid}]")
|
24
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(@redis))
|
18
25
|
@redis.errback do |reason|
|
19
26
|
raise "Connection to redis failed : #{reason}"
|
20
27
|
end
|
@@ -25,6 +32,10 @@ module Faye
|
|
25
32
|
"#{@name}/client_id"
|
26
33
|
end
|
27
34
|
|
35
|
+
def close_redis_connection
|
36
|
+
@redis&.close_connection
|
37
|
+
end
|
38
|
+
|
28
39
|
def fetch_client_id(&callback)
|
29
40
|
if @clientIdFetched == false
|
30
41
|
@clientIdFetched = true
|
@@ -48,6 +59,8 @@ module Faye
|
|
48
59
|
elsif message['channel'] == '/meta/handshake'
|
49
60
|
fetch_client_id do |clientId|
|
50
61
|
message['previousClientId'] = clientId if !clientId.nil?
|
62
|
+
# Store the clientId sent with the /meta/handshake
|
63
|
+
@sent_client_id = clientId
|
51
64
|
callback.call(message)
|
52
65
|
end
|
53
66
|
else
|
@@ -57,6 +70,7 @@ module Faye
|
|
57
70
|
|
58
71
|
def incoming(message, callback)
|
59
72
|
if message['channel'] == '/meta/handshake'
|
73
|
+
@on_handshake&.call(previous_client_id: @sent_client_id, new_client_id: message['clientId'])
|
60
74
|
if message['error'] == 'Already connected' && message.key?('clientId')
|
61
75
|
message.delete('error')
|
62
76
|
message['successful'] = true
|
@@ -3,7 +3,6 @@ require 'faye/reconnect'
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Faye::Reconnect::ClientExtension do
|
6
|
-
|
7
6
|
it 'requires a name option' do
|
8
7
|
expect {
|
9
8
|
Faye::Reconnect::ClientExtension.new
|
@@ -13,4 +12,11 @@ describe Faye::Reconnect::ClientExtension do
|
|
13
12
|
}.to_not raise_error
|
14
13
|
end
|
15
14
|
|
15
|
+
describe '#close_redis_connection' do
|
16
|
+
it 'calls #close_connection on the redis client' do
|
17
|
+
faye_reconnect = Faye::Reconnect::ClientExtension.new(name: 'foobar')
|
18
|
+
expect_any_instance_of(EventMachine::Hiredis::Client).to receive(:close_connection).and_return(true)
|
19
|
+
faye_reconnect.close_redis_connection
|
20
|
+
end
|
21
|
+
end
|
16
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faye-reconnect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Adrien Jarthon
|
7
8
|
- Adrien Siami
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: em-hiredis
|
@@ -28,58 +29,58 @@ dependencies:
|
|
28
29
|
name: bundler
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rake
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
+
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - "
|
60
|
+
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
+
version: '0'
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - "
|
67
|
+
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
+
version: '0'
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: rspec-eventmachine
|
71
72
|
requirement: !ruby/object:Gem::Requirement
|
72
73
|
requirements:
|
73
|
-
- - "
|
74
|
+
- - ">="
|
74
75
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
76
|
+
version: '0'
|
76
77
|
type: :development
|
77
78
|
prerelease: false
|
78
79
|
version_requirements: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
|
-
- - "
|
81
|
+
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
83
|
+
version: '0'
|
83
84
|
- !ruby/object:Gem::Dependency
|
84
85
|
name: thin
|
85
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +112,7 @@ dependencies:
|
|
111
112
|
description: Allow a long running faye client to reconnect to a faye server with the
|
112
113
|
same client ID
|
113
114
|
email:
|
114
|
-
-
|
115
|
+
- jobs@adrienjarthon.com
|
115
116
|
executables: []
|
116
117
|
extensions: []
|
117
118
|
extra_rdoc_files: []
|
@@ -150,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
151
|
- !ruby/object:Gem::Version
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
|
-
|
154
|
-
rubygems_version: 2.5.1
|
154
|
+
rubygems_version: 3.1.2
|
155
155
|
signing_key:
|
156
156
|
specification_version: 4
|
157
157
|
summary: Allow a long running faye client to reconnect to a faye server with the same
|