solid_cable 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -7
- data/app/models/jobs/solid_cable/prune_job.rb +9 -0
- data/app/models/solid_cable/message.rb +0 -4
- data/db/migrate/20240607184711_index_channels.rb +7 -0
- data/lib/action_cable/subscription_adapter/solid_cable.rb +1 -3
- data/lib/generators/solid_cable/install/install_generator.rb +9 -3
- data/lib/solid_cable/engine.rb +0 -8
- data/lib/solid_cable/version.rb +1 -1
- data/lib/solid_cable.rb +26 -14
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc6eab3ef9348ae133b005484482e8dccefe7c98aadeb8810ca23b632a976783
|
4
|
+
data.tar.gz: 1f867d1c133390a0894956c1c621e8e561b4bf1de14096196ae1768a541c59ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d6ffad7a1564e2e2aaa20cc5bf459fe630a6e739fb574c5eb0509ea6c3bfa31e38d47ac75a5ea74e2293c87804445d2700b9f4e1cecafd199724d07850cf433
|
7
|
+
data.tar.gz: 3caf1229b5582c91d9c06d7e18a32d79edff83c9453c2ca387b713b9d7caef985a4667faed648aa6c7a95c9174440594c3fd0e83b99d9c261dc9b9ee3259f99a
|
data/README.md
CHANGED
@@ -26,22 +26,34 @@ Now, you need to install the necessary migrations and configure Action Cable's a
|
|
26
26
|
$ bin/rails generate solid_cable:install
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
If you want to install to a different database you can pass an env variable.
|
30
|
+
```bash
|
31
|
+
$ DATABASE=cable bin/rails generate solid_cable:install
|
32
|
+
```
|
33
|
+
|
34
|
+
Update `config/cable.yml` to use the new adapter. connects_to is can be omitted
|
35
|
+
if you want to use the primary database.
|
30
36
|
|
31
37
|
```yaml
|
32
|
-
|
38
|
+
default: &default
|
33
39
|
adapter: solid_cable
|
40
|
+
polling_interval: 1.second
|
41
|
+
keep_messages_around_for: 1.day
|
42
|
+
|
43
|
+
development:
|
44
|
+
<<: *default
|
34
45
|
silence_polling: true
|
35
|
-
|
36
|
-
|
46
|
+
connects_to:
|
47
|
+
database:
|
48
|
+
writing: solid_cable_primary
|
49
|
+
reading: solid_cable_replica
|
37
50
|
|
38
51
|
test:
|
39
52
|
adapter: test
|
40
53
|
|
41
54
|
production:
|
42
|
-
|
43
|
-
polling_interval: 0.1
|
44
|
-
keep_messages_around_for: 10.minutes
|
55
|
+
<<: *default
|
56
|
+
polling_interval: 0.1.seconds
|
45
57
|
```
|
46
58
|
|
47
59
|
Finally, you need to run the migrations:
|
@@ -50,5 +62,10 @@ Finally, you need to run the migrations:
|
|
50
62
|
$ bin/rails db:migrate
|
51
63
|
```
|
52
64
|
|
65
|
+
By default messages are kept around forever. SolidCable ships with a job to
|
66
|
+
prune messages. You can run `SolidCable::PruneJob.perform_later` which removes
|
67
|
+
Messages that are older than what is specified in `keep_messages_around_for`
|
68
|
+
setting.
|
69
|
+
|
53
70
|
## License
|
54
71
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -11,7 +11,7 @@ module ActionCable
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def broadcast(channel, payload)
|
14
|
-
::SolidCable::Message.
|
14
|
+
::SolidCable::Message.insert({ channel:, payload: })
|
15
15
|
end
|
16
16
|
|
17
17
|
def subscribe(channel, callback, success_callback = nil)
|
@@ -64,8 +64,6 @@ module ActionCable
|
|
64
64
|
|
65
65
|
def remove_channel(channel)
|
66
66
|
channels.delete(channel)
|
67
|
-
|
68
|
-
::SolidCable::Message.prune
|
69
67
|
end
|
70
68
|
|
71
69
|
def invoke_callback(*)
|
@@ -3,13 +3,19 @@
|
|
3
3
|
class SolidCable::InstallGenerator < Rails::Generators::Base
|
4
4
|
source_root File.expand_path("templates", __dir__)
|
5
5
|
|
6
|
-
class_option :
|
6
|
+
class_option :database,
|
7
|
+
type: :string, aliases: %i(--db),
|
8
|
+
desc: "The database for your migration. By default, the " \
|
9
|
+
"current environment's primary database is used."
|
10
|
+
class_option :skip_migrations, type: :boolean, default: nil,
|
7
11
|
desc: "Skip migrations"
|
8
12
|
|
9
13
|
def create_migrations
|
10
14
|
return if options[:skip_migrations]
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
db_clause = "DATABASE=#{options[:database]}" if options[:database].present?
|
17
|
+
|
18
|
+
rails_command "railties:install:migrations FROM=solid_cable #{db_clause}".strip,
|
19
|
+
inline: true
|
14
20
|
end
|
15
21
|
end
|
data/lib/solid_cable/engine.rb
CHANGED
@@ -3,13 +3,5 @@
|
|
3
3
|
module SolidCable
|
4
4
|
class Engine < ::Rails::Engine
|
5
5
|
isolate_namespace SolidCable
|
6
|
-
|
7
|
-
config.solid_cable = ActiveSupport::OrderedOptions.new
|
8
|
-
|
9
|
-
initializer "solid_cable.config" do
|
10
|
-
config.solid_cable.each do |name, value|
|
11
|
-
SolidCable.public_send("#{name}=", value)
|
12
|
-
end
|
13
|
-
end
|
14
6
|
end
|
15
7
|
end
|
data/lib/solid_cable/version.rb
CHANGED
data/lib/solid_cable.rb
CHANGED
@@ -5,24 +5,36 @@ require "solid_cable/engine"
|
|
5
5
|
require "action_cable/subscription_adapter/solid_cable"
|
6
6
|
|
7
7
|
module SolidCable
|
8
|
-
|
8
|
+
class << self
|
9
|
+
def connects_to
|
10
|
+
cable_config.connects_to
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
def silence_polling?
|
14
|
+
!!cable_config.silence_polling
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def polling_interval
|
18
|
+
parse_duration(cable_config.polling_interval, default: 0.1.seconds)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
def keep_messages_around_for
|
22
|
+
parse_duration(cable_config.keep_messages_around_for, default: 1.day)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def cable_config
|
28
|
+
Rails.application.config_for("cable")
|
29
|
+
end
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
def parse_duration(duration, default:)
|
32
|
+
if duration.present?
|
33
|
+
*amount, units = duration.to_s.split(".")
|
34
|
+
amount.join(".").to_f.public_send(units)
|
35
|
+
else
|
36
|
+
default
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_cable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Pezza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,9 +48,11 @@ files:
|
|
34
48
|
- MIT-LICENSE
|
35
49
|
- README.md
|
36
50
|
- Rakefile
|
51
|
+
- app/models/jobs/solid_cable/prune_job.rb
|
37
52
|
- app/models/solid_cable/message.rb
|
38
53
|
- app/models/solid_cable/record.rb
|
39
54
|
- db/migrate/20240103034713_create_solid_cable_message.rb
|
55
|
+
- db/migrate/20240607184711_index_channels.rb
|
40
56
|
- lib/action_cable/subscription_adapter/solid_cable.rb
|
41
57
|
- lib/generators/solid_cable/install/USAGE
|
42
58
|
- lib/generators/solid_cable/install/install_generator.rb
|