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 +4 -4
- data/README.md +26 -32
- data/app/jobs/solid_cable/{prune_job.rb → trim_job.rb} +2 -2
- data/app/models/solid_cable/message.rb +2 -2
- data/lib/action_cable/subscription_adapter/solid_cable.rb +5 -1
- data/lib/generators/solid_cable/install/templates/config/cable.yml +1 -1
- data/lib/solid_cable/version.rb +1 -1
- data/lib/solid_cable.rb +6 -2
- data/lib/tasks/solid_cable_tasks.rake +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7ca96eb444763611b76694a5a950ea8f131cd2d5a0141b3897af849daf5492
|
4
|
+
data.tar.gz: a25ebf8ac69c71fab4f270e9602a5f25c12f3d6fbc29be5c5e84e27c91abf507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ba93aa71e565208f9201740583bb9cf77854ff9880dbad396b54e67d95f4cc8650765c910a4bb9c9e743c53abf1f7a20cdf77e596edf49cfc55da4d684e5ad2
|
7
|
+
data.tar.gz: a1b7c4824a957d14984cbf5c39936b6769241d5ae026da6abd2c17a94fc42326bedeedb32038682bf0e5491385e33364414b1dcc30c40d891abd8846f4e818b7
|
data/README.md
CHANGED
@@ -1,34 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# Solid Cable
|
2
2
|
|
3
|
-
Solid Cable is a
|
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
|
-
|
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
|
-
|
26
|
-
|
27
|
-
```
|
10
|
+
1. `bundle add solid_cable`
|
11
|
+
2. `bin/rails solid_cable:install`
|
28
12
|
|
29
|
-
This will
|
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
|
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.
|
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
|
-
|
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).
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module SolidCable
|
4
4
|
class Message < SolidCable::Record
|
5
|
-
scope :
|
6
|
-
where(created_at: ..::SolidCable.
|
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(*)
|
data/lib/solid_cable/version.rb
CHANGED
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
|
22
|
-
parse_duration(cable_config.
|
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
|
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:
|
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
|
+
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/
|
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
|