solid_cable 1.1.0 → 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: bfd23a7cb7209b15a906bea58757f19cc7eb94b6581e1b067af8a47a7f8038bb
4
- data.tar.gz: f3d94b8299931398c09178f136ef09c01ce221deac97c8456f5a93150714dfe6
3
+ metadata.gz: 7a7ca96eb444763611b76694a5a950ea8f131cd2d5a0141b3897af849daf5492
4
+ data.tar.gz: a25ebf8ac69c71fab4f270e9602a5f25c12f3d6fbc29be5c5e84e27c91abf507
5
5
  SHA512:
6
- metadata.gz: 06b9e7127dd9ffb5d57760a5da89bed82c68d0da1cbe54a8460eab5c7663dd49ebc9b7693a3237f7a481884b450f59c6a3d0cad82216153cd36bd9abbd3d7ed0
7
- data.tar.gz: b57dc804ae3e1e347ee99a649e48ead6e9d48aa4fb8bf5dbd4553e15d2b82af5d4440a6f73ae37f3e576be970a192524e5ca37bcd73c7ffd492cfd6fffdc143c
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
- ```
22
-
23
- Now, you need to run the installer:
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:
24
9
 
25
- ```bash
26
- $ bin/rails solid_cable:install
27
- ```
10
+ 1. `bundle add solid_cable`
11
+ 2. `bin/rails solid_cable:install`
28
12
 
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:
@@ -61,16 +45,9 @@ production:
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
53
  production:
@@ -79,8 +56,25 @@ production:
79
56
  database:
80
57
  writing: cable
81
58
  polling_interval: 0.1.seconds
82
- keep_messages_around_for: 1.day
59
+ message_retention: 1.day
83
60
  ```
84
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
+
85
78
  ## License
79
+
86
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(*)
@@ -10,4 +10,4 @@ production:
10
10
  database:
11
11
  writing: cable
12
12
  polling_interval: 0.1.seconds
13
- keep_messages_around_for: 1.day
13
+ message_retention: 1.day
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- VERSION = "1.1.0"
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- desc "Copy over the schema and set cache for Solid Cable"
3
+ desc "Copy over the schema and set cable adapter for Solid Cable"
4
4
  namespace :solid_cable do
5
5
  task :install do
6
6
  Rails::Command.invoke :generate, ["solid_cable:install"]
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.1.0
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-11 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,7 +34,7 @@ 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