solid_cable 0.3.0 → 1.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: 2a86a886aa1ce9834ba57de871e4d24539bac07799d4fae79add90fb62f5d3de
4
- data.tar.gz: 4bab771f89c8f57dbc9e6473d9ddf4e76dfa1136f6230d940b639de68b0e8fa2
3
+ metadata.gz: bc6eab3ef9348ae133b005484482e8dccefe7c98aadeb8810ca23b632a976783
4
+ data.tar.gz: 1f867d1c133390a0894956c1c621e8e561b4bf1de14096196ae1768a541c59ac
5
5
  SHA512:
6
- metadata.gz: a04ebc9e56a752312afe728b2b64b105b4b88c9f53b798b2028ddb5fb1e111ab33b89e6af006f8ebfb9b9080808f5d2ac512914db9656b46dca94252d41eb630
7
- data.tar.gz: c571e0388c3eb6ca10b054c920f5ece841ce5eae0940edbe87eea514b0812653bcc85a454de9653f5c56ee992f948787536e2ccf8de9436ad72520351e79e91e
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
- Update `config/cable.yml` to use the new adapter:
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
- development:
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
- polling_interval: 1
36
- keep_messages_around_for: 30.minutes
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
- adapter: solid_cable
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).
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidCable
4
+ class PruneJob < ActiveJob::Base
5
+ def perform
6
+ ::SolidCable::Message.prunable.delete_all
7
+ end
8
+ end
9
+ end
@@ -8,9 +8,5 @@ module SolidCable
8
8
  scope :broadcastable, lambda { |channels, last_id|
9
9
  where(channel: channels).where(id: (last_id + 1)..).order(:id)
10
10
  }
11
-
12
- def self.prune
13
- prunable.delete_all
14
- end
15
11
  end
16
12
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IndexChannels < ActiveRecord::Migration[7.1]
4
+ def change
5
+ add_index :solid_cable_messages, :channel, length: 500
6
+ end
7
+ end
@@ -11,7 +11,7 @@ module ActionCable
11
11
  end
12
12
 
13
13
  def broadcast(channel, payload)
14
- ::SolidCable::Message.create(channel:, payload:)
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 :skip_migrations, type: :boolean, default: nil,
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
- rails_command "railties:install:migrations FROM=solid_cable", inline: true
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- VERSION = "0.3.0"
4
+ VERSION = "1.0.0"
5
5
  end
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
- mattr_accessor :connects_to
8
+ class << self
9
+ def connects_to
10
+ cable_config.connects_to
11
+ end
9
12
 
10
- def self.silence_polling?
11
- !!Rails.application.config_for("cable")[:silence_polling]
12
- end
13
+ def silence_polling?
14
+ !!cable_config.silence_polling
15
+ end
13
16
 
14
- def self.polling_interval
15
- Rails.application.config_for("cable")[:polling_interval].presence || 0.1
16
- end
17
+ def polling_interval
18
+ parse_duration(cable_config.polling_interval, default: 0.1.seconds)
19
+ end
17
20
 
18
- def self.keep_messages_around_for
19
- duration = Rails.application.config_for("cable")[:keep_messages_around_for]
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
- if duration.present?
22
- amount, units = duration.to_s.split(".")
23
- amount.to_i.public_send(units)
24
- else
25
- 30.minutes
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.3.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-05-28 00:00:00.000000000 Z
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