solid_cable 0.2.3 → 1.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: d8096f76e264285fd4961d3acc29b899bf8a6a9d253a9d8229a767c224b2ddc9
4
- data.tar.gz: f19299d3a1b31e59178da3af4f0a114e8c73bfc542ecb09a5cce15ce48c17563
3
+ metadata.gz: bc6eab3ef9348ae133b005484482e8dccefe7c98aadeb8810ca23b632a976783
4
+ data.tar.gz: 1f867d1c133390a0894956c1c621e8e561b4bf1de14096196ae1768a541c59ac
5
5
  SHA512:
6
- metadata.gz: 2b298fc20cfda3365df1e02e8eea12fd23e2b7c831075353c4b75a179a83777caba6f1516f10562b993ffe2a7a86d8d95d5f92952de8b2c690428b0448fc7d27
7
- data.tar.gz: 066cbb2f2a661c58769ef760519cac757323d0fd6f329ca07caa107cce81a741d03b55e4adc8484307580edcd5b8046d42fee8706017da102bfd36c428de8918
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.2.3"
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,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
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-01-03 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
16
30
  requirements:
17
- - - "~>"
31
+ - - "<"
18
32
  - !ruby/object:Gem::Version
19
- version: '7.1'
33
+ version: '9'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - "<"
25
39
  - !ruby/object:Gem::Version
26
- version: '7.1'
40
+ version: '9'
27
41
  description: Database-backed Action Cable backend.
28
42
  email:
29
43
  - pezza@hey.com
@@ -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
@@ -65,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
81
  - !ruby/object:Gem::Version
66
82
  version: '0'
67
83
  requirements: []
68
- rubygems_version: 3.5.3
84
+ rubygems_version: 3.5.10
69
85
  signing_key:
70
86
  specification_version: 4
71
87
  summary: Database-backed Action Cable backend.