Skip to content

Commit

Permalink
Replace litestack with solid_cable for action cable adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
aidewoode committed Oct 17, 2024
1 parent c5da899 commit bbb7489
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 42 deletions.
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ gem "solid_cache", "~> 1.0.0"
# Background job processing
gem "solid_queue", "~> 0.2.1"

# Default stack for pub/sub
# Because there is an error while using with Rails 7.2, the fix is not released yet.
# So we use the main branch for now.
gem "litestack", git: "https://github.com/oldmoe/litestack.git", branch: "master"
# Action Cable adapter
gem "solid_cable", "~> 3.0.0"

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.13.0"
Expand Down
25 changes: 6 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
GIT
remote: https://github.com/oldmoe/litestack.git
revision: 83a1dc5f788bee673a696ca2d6df551a84799bb4
branch: master
specs:
litestack (0.4.4)
erubi (~> 1)
oj (~> 3)
rack (~> 3)
rackup (~> 2)
sqlite3 (>= 1.6.0, < 2.0.0)
tilt (~> 2)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -234,10 +221,6 @@ GEM
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oj (3.16.6)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.0)
pagy (6.0.4)
parallel (1.25.1)
parser (3.3.1.0)
Expand Down Expand Up @@ -340,6 +323,11 @@ GEM
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_properties (1.17.0)
solid_cable (3.0.2)
actioncable (>= 7.2)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_cache (1.0.6)
activejob (>= 7.2)
activerecord (>= 7.2)
Expand All @@ -365,7 +353,6 @@ GEM
railties (>= 6.0.0)
stringio (3.1.1)
thor (1.3.2)
tilt (2.4.0)
timeout (0.4.1)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -417,7 +404,6 @@ DEPENDENCIES
jsbundling-rails (~> 1.3.0)
kamal (~> 1.4.0)
listen (~> 3.9.0)
litestack!
memory_profiler (~> 0.9.13)
pagy (~> 6.0.0)
parallel (~> 1.25.0)
Expand All @@ -428,6 +414,7 @@ DEPENDENCIES
ransack (~> 4.2.0)
simplecov (~> 0.22.0)
simplecov-lcov (~> 0.8.0)
solid_cable (~> 3.0.0)
solid_cache (~> 1.0.0)
solid_queue (~> 0.2.1)
sqlite3 (~> 1.7.0)
Expand Down
5 changes: 3 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module BlackCandy

has_config :db_url
has_config :cache_db_url
has_config :cable_db_url
has_config :media_path
has_config :db_adapter, default: "sqlite"
has_config :nginx_sendfile, default: false
Expand All @@ -42,8 +43,8 @@ module BlackCandy

if value == "postgresql" &&
ENV["RAILS_ENV"] == "production" &&
(config.db_url.blank? || config.cache_db_url.blank?)
raise_config_validation_error "DB_URL and CACHE_DB_URL are required if database adapter is postgresql"
(config.db_url.blank? || config.cache_db_url.blank? || config.cable_db_url.blank?)
raise_config_validation_error "DB_URL, CABLE_DB_URL and CACHE_DB_URL are required if database adapter is postgresql"
end
end

Expand Down
26 changes: 10 additions & 16 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
sqlite_default: &sqlite_default
adapter: litecable
default: &default
adapter: solid_cable
connects_to:
database:
writing: cable
polling_interval: 0.1.seconds
message_retention: 1.day

pg_default: &pg_default
adapter: postgresql
development:
<<: *default

test:
adapter: test

<% if BlackCandy.config.db_adapter == "postgresql" %>
development:
<<: *pg_default

production:
<<: *pg_default
<% else %>
development:
<<: *sqlite_default

production:
<<: *sqlite_default
<% end %>
<<: *default
24 changes: 24 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ development:
<<: *primary_development
database: blackcandy_development_cache
migrations_paths: db/cache_migrate
cable:
<<: *primary_development
database: blackcandy_development_cable
migrations_paths: db/cable_migrate

test:
primary: &primary_test
Expand All @@ -33,6 +37,10 @@ test:
<<: *primary_test
database: blackcandy_test_cache
migrations_paths: db/cache_migrate
cable:
<<: *primary_test
database: blackcandy_test_cable
migrations_paths: db/cable_migrate

production:
primary: &primary_production
Expand All @@ -42,6 +50,10 @@ production:
<<: *primary_production
url: <%= BlackCandy.config.cache_db_url %>
migrations_paths: db/cache_migrate
cable:
<<: *primary_production
url: <%= BlackCandy.config.cable_db_url %>
migrations_paths: db/cable_migrate
<% else %>
development:
primary:
Expand All @@ -51,6 +63,10 @@ development:
<<: *sqlite_default
database: storage/development_cache.sqlite3
migrations_paths: db/cache_migrate
cable:
<<: *sqlite_default
database: storage/development_cable.sqlite3
migrations_paths: db/cable_migrate

test:
primary:
Expand All @@ -60,6 +76,10 @@ test:
<<: *sqlite_default
database: storage/test_cache.sqlite3
migrations_paths: db/cache_migrate
cable:
<<: *sqlite_default
database: storage/test_cable.sqlite3
migrations_paths: db/cable_migrate

production:
primary:
Expand All @@ -69,4 +89,8 @@ production:
<<: *sqlite_default
database: storage/production_cache.sqlite3
migrations_paths: db/cache_migrate
cable:
<<: *sqlite_default
database: storage/production_cable.sqlite3
migrations_paths: db/cable_migrate
<% end %>
11 changes: 11 additions & 0 deletions db/cable_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ActiveRecord::Schema[7.1].define(version: 1) do
create_table "solid_cable_messages", force: :cascade do |t|
t.binary "channel", limit: 1024, null: false
t.binary "payload", limit: 536870912, null: false
t.datetime "created_at", null: false
t.integer "channel_hash", limit: 8, null: false
t.index ["channel"], name: "index_solid_cable_messages_on_channel"
t.index ["channel_hash"], name: "index_solid_cable_messages_on_channel_hash"
t.index ["created_at"], name: "index_solid_cable_messages_on_created_at"
end
end
8 changes: 7 additions & 1 deletion test/lib/black_candy/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ class BlackCandy::ConfigTest < ActiveSupport::TestCase
end
end

with_env("DB_ADAPTER" => "postgresql", "DB_URL" => "database_url", "CACHE_DB_URL" => "cache_db_url", "RAILS_ENV" => "production") do
with_env(
"DB_ADAPTER" => "postgresql",
"DB_URL" => "database_url",
"CABLE_DB_URL" => "cable_db_url",
"CACHE_DB_URL" => "cache_db_url",
"RAILS_ENV" => "production"
) do
assert_equal "postgresql", BlackCandy.config.db_adapter
end
end
Expand Down

0 comments on commit bbb7489

Please sign in to comment.