action-cable-redis-backport 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +18 -0
- data/lib/action-cable-redis-backport.rb +81 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f6626b2fe4b7b0fd3993703be212c4f7c7f77976805827aaa11c4b1169abae9
|
4
|
+
data.tar.gz: 5431c9c597ee6b58a1f532482d004cda7cd2d315e82bb0dd9b6aba784523019f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e2c8f8e587c7cf9a4c34889affc53c5734a7f226398eda1bdfd54cbf6ed971ecbdb7fc78d4e9e20457ef5bfe021b9d30145ccc6a40959d80b92b7a21b2f58ce
|
7
|
+
data.tar.gz: a07efe7c9d5c81a36aea1e3604a0a86fa4e7b2642f1232eab34a5fbdd4368e3f5146428a79062f16aa03afc51fa7b01833254b64d1f3c3800d9efa9ae927fd78
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2021 Vladimir Dementyev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/action-cable-redis-backport.svg)](https://rubygems.org/gems/action-cable-redis-backport)
|
2
|
+
|
3
|
+
# Action Cable 7.1 Redis pub/sub backport
|
4
|
+
|
5
|
+
This gem backport Redis adapter with connection failure recovery support from Rails 7.1: [https://github.com/rails/rails/pull/46562](https://github.com/rails/rails/pull/46562).
|
6
|
+
|
7
|
+
Works with Rails 5+.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Install the gem:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
# Gemfile
|
15
|
+
gem "action-cable-redis-backport"
|
16
|
+
```
|
17
|
+
|
18
|
+
That's it!
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_cable"
|
4
|
+
|
5
|
+
return if ActionCable::VERSION::MAJOR >= 7 && ActionCable::VERSION::MINOR >= 1
|
6
|
+
|
7
|
+
require "action_cable/subscription_adapter/redis"
|
8
|
+
|
9
|
+
module ActionCableRedisBackport
|
10
|
+
ActionCable::SubscriptionAdapter::Redis::Listener.prepend(Module.new do
|
11
|
+
def initialize(*)
|
12
|
+
super
|
13
|
+
|
14
|
+
return if instance_variable_defined?(:@reconnect_attempt)
|
15
|
+
|
16
|
+
@subscribed_client = @raw_client = nil
|
17
|
+
|
18
|
+
@reconnect_attempt = 0
|
19
|
+
@reconnect_attempts = ::ActionCable.server.config.cable&.fetch("reconnect_attempts", 1)
|
20
|
+
@reconnect_attempts = Array.new(@reconnect_attempts, 0) if @reconnect_attempts.is_a?(Integer)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
if ::Redis::VERSION < "5"
|
25
|
+
ConnectionError = ::Redis::ConnectionError
|
26
|
+
else
|
27
|
+
ConnectionError = RedisClient::ConnectionError
|
28
|
+
end
|
29
|
+
|
30
|
+
def ensure_listener_running
|
31
|
+
@thread ||= Thread.new do
|
32
|
+
Thread.current.abort_on_exception = true
|
33
|
+
|
34
|
+
begin
|
35
|
+
conn = @adapter.redis_connection_for_subscriptions
|
36
|
+
listen conn
|
37
|
+
rescue ConnectionError
|
38
|
+
reset
|
39
|
+
if retry_connecting?
|
40
|
+
when_connected { resubscribe }
|
41
|
+
retry
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def retry_connecting?
|
48
|
+
@reconnect_attempt += 1
|
49
|
+
|
50
|
+
return false if @reconnect_attempt > @reconnect_attempts.size
|
51
|
+
|
52
|
+
sleep_t = @reconnect_attempts[@reconnect_attempt - 1]
|
53
|
+
|
54
|
+
sleep(sleep_t) if sleep_t > 0
|
55
|
+
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def resubscribe
|
60
|
+
channels = @sync.synchronize do
|
61
|
+
@subscribers.keys
|
62
|
+
end
|
63
|
+
return if channels.empty?
|
64
|
+
|
65
|
+
if @subscribed_client
|
66
|
+
@subscribed_client.subscribe(*channels)
|
67
|
+
else
|
68
|
+
send_command("subscribe", *channels)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def reset
|
73
|
+
@subscription_lock.synchronize do
|
74
|
+
@subscribed_client = @raw_client = nil
|
75
|
+
@subscribe_callbacks.clear
|
76
|
+
@when_connected.clear
|
77
|
+
when_connected { @reconnect_attempt = 0 }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end)
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action-cable-redis-backport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladimir Dementyev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actioncable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.15'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.15'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '13.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '13.0'
|
61
|
+
description: Backports Action Cable 7.1 Redis adapter for older versions
|
62
|
+
email:
|
63
|
+
- dementiev.vm@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- lib/action-cable-redis-backport.rb
|
71
|
+
homepage: http://github.com/palkan/action-cable-redis-backport
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata:
|
75
|
+
bug_tracker_uri: http://github.com/palkan/action-cable-redis-backport/issues
|
76
|
+
changelog_uri: https://github.com/palkan/action-cable-redis-backport/blob/master/CHANGELOG.md
|
77
|
+
documentation_uri: http://github.com/palkan/action-cable-redis-backport
|
78
|
+
homepage_uri: http://github.com/palkan/action-cable-redis-backport
|
79
|
+
source_code_uri: http://github.com/palkan/action-cable-redis-backport
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.6'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.3.11
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Backports Action Cable 7.1 Redis adapter for older versions
|
99
|
+
test_files: []
|