solid_cable 3.0.12 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bb120f549ab39af171e93f67350d0ca6b44d2d43e42e23d538c74f894a8e4d4
4
- data.tar.gz: 13404708ae736ed703e80623b0b8496bbaca984cee263a97818951abb94fe35c
3
+ metadata.gz: 82d0f5f6a07f329cf8365e30926b72879b22300fab4c7520d18c865dc184156a
4
+ data.tar.gz: 7e9bd94004f0111b403b31b30f9aa6eb489173f523af656a2db76f771fc7a7c0
5
5
  SHA512:
6
- metadata.gz: 5fc3825837aa2ee2ff4e805e40a45a2c19471576f91d0f9a0603fdb679542e2a473dd2797cd2a0bf795785ea65d713b01c2c3d0f2ef3bdcdba100608a3cf6115
7
- data.tar.gz: 1b9474761a35f8aa38063128b6c4fb3a9c30ae94b995e80d1f17eb590cf47ff84f684f557328448d8cc4aa2a26ba509b9b6c32f7ad179d140f9cc23cccca94e9
6
+ metadata.gz: adc3ddc71a3033b4bea6fdd5cc94cf54ca29c39d527d763c0476cd0a99639f94fea18f7a4dd43729da1a20bcb179f900cc95167ac3ea3b95e7186dcd9b048e30
7
+ data.tar.gz: 96ac0c12361e6a9e39a1f5fe0c33975d437e3f6dc1e9038ddda243eef49390bf7078a03d7da7901a4b286f1bd3fc50d9a5edb3caf3877ab887af3ee51d238b64
data/README.md CHANGED
@@ -86,6 +86,8 @@ The options are:
86
86
  - `silence_polling` - whether to silence Active Record logs emitted when polling (Defaults to true)
87
87
  - `use_skip_locked` - whether to use `FOR UPDATE SKIP LOCKED` when performing trimming. This will be automatically detected in the future, and for now, you'd only need to set this to `false` if your database doesn't support it. For MySQL, that'd be versions < 8, and for PostgreSQL, versions < 9.5. If you use SQLite, this has no effect, as writes are sequential. (Defaults to true)
88
88
  - `trim_batch_size` - the batch size to use when deleting old records (default: `100`)
89
+ - `reconnect_attempts` - Supports a number of connection attempts or an array of
90
+ durations to wait between attempts. (Defaults to 1 retry attempt)
89
91
 
90
92
 
91
93
  ## Trimming
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "bundler/setup"
4
2
 
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
5
6
  require "bundler/gem_tasks"
@@ -39,6 +39,11 @@ module ActionCable
39
39
  end
40
40
 
41
41
  class Listener < ::ActionCable::SubscriptionAdapter::SubscriberMap
42
+ CONNECTION_ERRORS = [
43
+ ActiveRecord::ConnectionFailed,
44
+ ActiveRecord::ConnectionTimeoutError,
45
+ ActiveRecord::ConnectionNotEstablished
46
+ ]
42
47
  Stop = Class.new(Exception)
43
48
 
44
49
  def initialize(event_loop)
@@ -51,11 +56,18 @@ module ActionCable
51
56
  # for specific sections of code, rather than acquired.
52
57
  @critical = Concurrent::Semaphore.new(0)
53
58
 
59
+ @reconnect_attempt = 0
60
+ @last_id = last_message_id
61
+
54
62
  @thread = Thread.new do
55
63
  Thread.current.name = "solid_cable_listener"
56
64
  Thread.current.report_on_exception = true
57
65
 
58
- listen
66
+ begin
67
+ listen
68
+ rescue *CONNECTION_ERRORS
69
+ retry if retry_connecting?
70
+ end
59
71
  end
60
72
  end
61
73
 
@@ -106,11 +118,7 @@ module ActionCable
106
118
 
107
119
  private
108
120
  attr_reader :event_loop, :thread
109
- attr_writer :last_id
110
-
111
- def last_id
112
- @last_id ||= last_message_id
113
- end
121
+ attr_accessor :last_id, :reconnect_attempt
114
122
 
115
123
  def last_message_id
116
124
  ::SolidCable::Message.maximum(:id) || 0
@@ -146,6 +154,22 @@ module ActionCable
146
154
  yield
147
155
  end
148
156
  end
157
+
158
+ def reconnect_attempts
159
+ @reconnect_attempts ||= ::SolidCable.reconnect_attempts
160
+ end
161
+
162
+ def retry_connecting?
163
+ self.reconnect_attempt += 1
164
+
165
+ return false if reconnect_attempt > reconnect_attempts.size
166
+
167
+ sleep_t = reconnect_attempts[reconnect_attempt - 1]
168
+
169
+ sleep(sleep_t) if sleep_t > 0
170
+
171
+ true
172
+ end
149
173
  end
150
174
  end
151
175
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- VERSION = "3.0.12"
4
+ VERSION = "4.0.0"
5
5
  end
data/lib/solid_cable.rb CHANGED
@@ -48,6 +48,12 @@ module SolidCable
48
48
  2
49
49
  end
50
50
 
51
+ def reconnect_attempts
52
+ attempts = cable_config.fetch(:reconnect_attempts, 1)
53
+ attempts = Array.new(attempts, 0) if attempts.is_a?(Integer)
54
+ attempts
55
+ end
56
+
51
57
  private
52
58
  def cable_config
53
59
  Rails.application.config_for("cable")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.12
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
@@ -65,6 +65,20 @@ dependencies:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '7.2'
68
+ - !ruby/object:Gem::Dependency
69
+ name: minitest
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.0'
68
82
  description: Database-backed Action Cable backend.
69
83
  email:
70
84
  - pezza@hey.com
@@ -88,7 +102,6 @@ files:
88
102
  - lib/generators/solid_cable/update/update_generator.rb
89
103
  - lib/solid_cable.rb
90
104
  - lib/solid_cable/engine.rb
91
- - lib/solid_cable/railtie.rb
92
105
  - lib/solid_cable/version.rb
93
106
  - lib/tasks/solid_cable_tasks.rake
94
107
  homepage: https://github.com/rails/solid_cable
@@ -105,14 +118,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
118
  requirements:
106
119
  - - ">="
107
120
  - !ruby/object:Gem::Version
108
- version: 3.1.0
121
+ version: 3.3.0
109
122
  required_rubygems_version: !ruby/object:Gem::Requirement
110
123
  requirements:
111
124
  - - ">="
112
125
  - !ruby/object:Gem::Version
113
126
  version: '0'
114
127
  requirements: []
115
- rubygems_version: 3.6.9
128
+ rubygems_version: 4.0.10
116
129
  specification_version: 4
117
130
  summary: Database-backed Action Cable backend.
118
131
  test_files: []
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidCable
4
- class Railtie < ::Rails::Railtie
5
- end
6
- end