solid_cable 1.0.6 → 2.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: 6a3ffe8d513e578210ffa1586b9f3fa921919ab9ff1d4b2a9cbf802ea550a37c
4
- data.tar.gz: 9dab848172317e0046d8beced7fe6f3e889b1190c91e5e9be10b2f6b964e6780
3
+ metadata.gz: 7a7ca96eb444763611b76694a5a950ea8f131cd2d5a0141b3897af849daf5492
4
+ data.tar.gz: a25ebf8ac69c71fab4f270e9602a5f25c12f3d6fbc29be5c5e84e27c91abf507
5
5
  SHA512:
6
- metadata.gz: 07f016353535c742c511d63dfc600d78e381963567b89ece4ba194b357e0c89bcc2633b40e1d8b7cd6c062ff27d15e316a3b8c99ed36f04cea6163e33d034dde
7
- data.tar.gz: e6affe9d7b555a0892aae14092368d46392f7fcc6f563c7bce91353e3bae046a444dbc28148bc10a2ffbb08d0872aaf2e401a5bf5151ac9fa2d23c51e3b72df9
6
+ metadata.gz: 7ba93aa71e565208f9201740583bb9cf77854ff9880dbad396b54e67d95f4cc8650765c910a4bb9c9e743c53abf1f7a20cdf77e596edf49cfc55da4d684e5ad2
7
+ data.tar.gz: a1b7c4824a957d14984cbf5c39936b6769241d5ae026da6abd2c17a94fc42326bedeedb32038682bf0e5491385e33364414b1dcc30c40d891abd8846f4e818b7
data/README.md CHANGED
@@ -1,34 +1,18 @@
1
- # SolidCable
1
+ # Solid Cable
2
2
 
3
- Solid Cable is a DB-based backend for Action Cable.
3
+ Solid Cable is a database-backed Action Cable adapter that keeps messages in a table and continously polls for updates. This makes it possible to drop the common dependency on Redis, if it isn't needed for any other purpose. Despite polling, the performance of Solid Cable is comparable to Redis in most situations. And in all circumstances, it makes it easier to deploy Rails when Redis is no longer a required dependency for Action Cable functionality.
4
4
 
5
5
 
6
6
  ## Installation
7
- Add this line to your application's Gemfile:
8
7
 
9
- ```ruby
10
- gem "solid_cable"
11
- ```
12
-
13
- And then execute:
14
- ```bash
15
- $ bundle
16
- ```
17
-
18
- Or install it yourself as:
19
- ```bash
20
- $ gem install solid_cable
21
- ```
8
+ Solid Cable is configured by default in new Rails 8 applications. But if you're running an earlier version, you can add it manually following these steps:
22
9
 
23
- Now, you need to run the installer:
10
+ 1. `bundle add solid_cable`
11
+ 2. `bin/rails solid_cable:install`
24
12
 
25
- ```bash
26
- $ bin/rails generate solid_cable:install
27
- ```
28
-
29
- This will create the `db/cable_schema.rb` file.
13
+ This will configure Solid Cable as the production cable adapter by overwritting `config/cable.yml` and create `db/cable_schema.rb`.
30
14
 
31
- You will then have to add the configuration for the database in `config/database.yml`. If you're using SQLite, it'll look something like this:
15
+ You will then have to add the configuration for the cable database in `config/database.yml`. If you're using SQLite, it'll look like this:
32
16
 
33
17
  ```yaml
34
18
  production:
@@ -57,42 +41,40 @@ production:
57
41
  ```
58
42
 
59
43
  > [!NOTE]
60
- > Calling `bin/rails generate solid_cable:install` will automatically setup `config/cable.yml`, so no additional configuration is needed there (although you must make sure that you use the `cable` name in `database.yml` for this to match!). But if you want to use Solid Cable in a different environment (like staging or even development), you'll have to manually add that `connects_to` block to the respective environment in the `config/cable.yml` file. And, as always, make sure that the name you're using for the database in `config/cable.yml` matches the name you define in `config/database.yml`.
44
+ > Calling `bin/rails solid_cable:install` will automatically setup `config/cable.yml`, so no additional configuration is needed there (although you must make sure that you use the `cable` name in `database.yml` for this to match!). But if you want to use Solid Cable in a different environment (like staging or even development), you'll have to manually add that `connects_to` block to the respective environment in the `config/cable.yml` file. And, as always, make sure that the name you're using for the database in `config/cable.yml` matches the name you define in `config/database.yml`.
61
45
 
62
46
  Then run `db:prepare` in production to ensure the database is created and the schema is loaded.
63
47
 
64
- ## Usage
65
-
66
- By default messages are kept around forever. SolidCable ships with a job to
67
- prune messages. You can run `SolidCable::PruneJob.perform_later` which removes
68
- Messages that are older than what is specified in `keep_messages_around_for`
69
- setting.
70
-
71
48
  ## Configuration
72
49
 
73
- All configuration is managed via the `config/cable.yml`file. To use Solid Cable, the `adapter` value *must be* `solid_cable`. When using Solid Cable, the other values you can set are: `connects_to`, `polling_interval`, `silence_polling`, and `keep_messages_around_for`. For example:
50
+ All configuration is managed via the `config/cable.yml` file. By default, it'll be configured like this:
74
51
 
75
52
  ```yaml
76
- default: &default
53
+ production:
77
54
  adapter: solid_cable
78
- polling_interval: 1.second
79
- keep_messages_around_for: 1.day
80
-
81
- development:
82
- <<: *default
83
- silence_polling: true
84
55
  connects_to:
85
56
  database:
86
- writing: solid_cable_primary
87
- reading: solid_cable_replica
88
-
89
- test:
90
- adapter: test
91
-
92
- production:
93
- <<: *default
57
+ writing: cable
94
58
  polling_interval: 0.1.seconds
59
+ message_retention: 1.day
95
60
  ```
96
61
 
62
+ The options are:
63
+
64
+ - `connects_to` - set the Active Record database configuration for the Solid Cable models. All options available in Active Record can be used here.
65
+ - `polling_interval` - sets the frequency of the polling interval. (Defaults to
66
+ 0.1.seconds)
67
+ - `message_retention` - sets the retention time for messages kept in the database. Used as the cut-off when trimming is performed. (Defaults to 1.day)
68
+ - `autotrim` - sets wether you want Solid Cable to handle autotrimming messages. (Defaults to true)
69
+ - `silence_polling` - whether to silence Active Record logs emitted when polling (Defaults to true)
70
+
71
+ ## Trimming
72
+
73
+ Messages are autotrimmed based upon the `message_retention` setting to determine how long messages are to be kept around. If no `message_retention` is given or parsing fails, it defaults to `1.day`. Messages are trimmed when a subscriber unsubscribes.
74
+
75
+ Autotrimming can negatively impact performance depending on your workload because it is doing a delete on ubsubscribe. If
76
+ you would prefer, you can disable autotrimming by setting `autotrim: false` and you can manually enqueue the job later, `SolidCable::TrimJob.perform_later`, or run it on a recurring interval out of band.
77
+
97
78
  ## License
79
+
98
80
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- class PruneJob < ActiveJob::Base
4
+ class TrimJob < ActiveJob::Base
5
5
  def perform
6
- ::SolidCable::Message.prunable.delete_all
6
+ ::SolidCable::Message.trimmable.delete_all
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module SolidCable
4
4
  class Message < SolidCable::Record
5
- scope :prunable, lambda {
6
- where(created_at: ..::SolidCable.keep_messages_around_for.ago)
5
+ scope :trimmable, lambda {
6
+ where(created_at: ..::SolidCable.message_retention.ago)
7
7
  }
8
8
  scope :broadcastable, lambda { |channels, last_id|
9
9
  where(channel: channels).where(id: (last_id + 1)..).order(:id)
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "action_cable/subscription_adapter/base"
4
+
3
5
  module ActionCable
4
6
  module SubscriptionAdapter
5
- class SolidCable < Base
7
+ class SolidCable < ::ActionCable::SubscriptionAdapter::Base
6
8
  prepend ChannelPrefix
7
9
 
8
10
  def initialize(*)
@@ -64,6 +66,8 @@ module ActionCable
64
66
 
65
67
  def remove_channel(channel)
66
68
  channels.delete(channel)
69
+
70
+ ::SolidCable::TrimJob.perform_now if ::SolidCable.autotrim?
67
71
  end
68
72
 
69
73
  def invoke_callback(*)
@@ -3,48 +3,8 @@
3
3
  class SolidCable::InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path("templates", __dir__)
5
5
 
6
- def add_solid_errors_db_schema
6
+ def copy_files
7
7
  template "db/cable_schema.rb"
8
- end
9
-
10
- def configure_production_cable
11
- gsub_file("config/cable.yml",
12
- /production:\n(^\s*.*$\n){2,}/,
13
- new_production_cable_config)
14
- end
15
-
16
- def configure_development_cable
17
- gsub_file("config/cable.yml",
18
- /development:\n\s*adapter: redis\n url: .*\n/,
19
- new_development_cable_config)
20
- end
21
-
22
- private
23
-
24
- def new_production_cable_config
25
- <<~YAML
26
- production:
27
- adapter: solid_cable
28
- connects_to:
29
- database:
30
- writing: cable
31
- reading: cable
32
- polling_interval: 0.1.seconds
33
- keep_messages_around_for: 1.day
34
- YAML
35
- end
36
-
37
- def new_development_cable_config
38
- <<~YAML
39
- development:
40
- adapter: solid_cable
41
- connects_to:
42
- database:
43
- writing: cable
44
- reading: cable
45
- polling_interval: 1.second
46
- keep_messages_around_for: 1.day
47
- silence_polling: true
48
- YAML
8
+ template "config/cable.yml", force: true
49
9
  end
50
10
  end
@@ -0,0 +1,13 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: test
6
+
7
+ production:
8
+ adapter: solid_cable
9
+ connects_to:
10
+ database:
11
+ writing: cable
12
+ polling_interval: 0.1.seconds
13
+ message_retention: 1.day
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- VERSION = "1.0.6"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/solid_cable.rb CHANGED
@@ -18,8 +18,12 @@ module SolidCable
18
18
  parse_duration(cable_config.polling_interval, default: 0.1.seconds)
19
19
  end
20
20
 
21
- def keep_messages_around_for
22
- parse_duration(cable_config.keep_messages_around_for, default: 1.day)
21
+ def message_retention
22
+ parse_duration(cable_config.message_retention, default: 1.day)
23
+ end
24
+
25
+ def autotrim?
26
+ cable_config.autotrim != false
23
27
  end
24
28
 
25
29
  private
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc "Copy over the schema and set cable adapter for Solid Cable"
4
+ namespace :solid_cable do
5
+ task :install do
6
+ Rails::Command.invoke :generate, ["solid_cable:install"]
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 2.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-09-10 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,17 +34,19 @@ files:
34
34
  - MIT-LICENSE
35
35
  - README.md
36
36
  - Rakefile
37
- - app/jobs/solid_cable/prune_job.rb
37
+ - app/jobs/solid_cable/trim_job.rb
38
38
  - app/models/solid_cable/message.rb
39
39
  - app/models/solid_cable/record.rb
40
40
  - lib/action_cable/subscription_adapter/solid_cable.rb
41
41
  - lib/generators/solid_cable/install/USAGE
42
42
  - lib/generators/solid_cable/install/install_generator.rb
43
+ - lib/generators/solid_cable/install/templates/config/cable.yml
43
44
  - lib/generators/solid_cable/install/templates/db/cable_schema.rb
44
45
  - lib/solid_cable.rb
45
46
  - lib/solid_cable/engine.rb
46
47
  - lib/solid_cable/railtie.rb
47
48
  - lib/solid_cable/version.rb
49
+ - lib/tasks/solid_cable_tasks.rake
48
50
  homepage: http://github.com/npezza93/solid_cable
49
51
  licenses:
50
52
  - MIT