From 97b0460f38e1267ab5d59da837aff312aaf7f697 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 17 Jan 2025 00:15:27 -0500 Subject: [PATCH 1/3] Install solid_cable --- Gemfile | 1 + Gemfile.lock | 6 ++++++ config/cable.yml | 13 ++++++++++--- config/database.yml | 4 ++++ db/cable_schema.rb | 11 +++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 db/cable_schema.rb diff --git a/Gemfile b/Gemfile index c57898b..8f6e696 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem "jbuilder" # Use Redis adapter to run Action Cable in production # gem "redis", ">= 4.0.1" +gem "solid_cable" gem "solid_cache" gem "solid_queue" diff --git a/Gemfile.lock b/Gemfile.lock index dc00648..0db942b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -259,6 +259,11 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + solid_cable (3.0.5) + actioncable (>= 7.2) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) solid_cache (1.0.6) activejob (>= 7.2) activerecord (>= 7.2) @@ -327,6 +332,7 @@ DEPENDENCIES rails! rubocop-rails-omakase selenium-webdriver + solid_cable solid_cache solid_queue sqlite3 (>= 1.4) diff --git a/config/cable.yml b/config/cable.yml index b70279b..b9adc5a 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,3 +1,7 @@ +# Async adapter only works within the same process, so for manually triggering cable updates from a console, +# and seeing results in the browser, you must do so from the web console (running inside the dev process), +# not a terminal started via bin/rails console! Add "console" to any action or any ERB template view +# to make the web console appear. development: adapter: async @@ -5,6 +9,9 @@ test: adapter: test production: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: family_budget_production + adapter: solid_cable + connects_to: + database: + writing: cable + polling_interval: 0.1.seconds + message_retention: 1.day diff --git a/config/database.yml b/config/database.yml index c5a9bfb..64847cf 100644 --- a/config/database.yml +++ b/config/database.yml @@ -42,3 +42,7 @@ production: <<: *default database: storage/production_queue.sqlite3 migrations_paths: db/queue_migrate + cable: + <<: *default + database: storage/production_cable.sqlite3 + migrations_paths: db/cable_migrate diff --git a/db/cable_schema.rb b/db/cable_schema.rb new file mode 100644 index 0000000..2366660 --- /dev/null +++ b/db/cable_schema.rb @@ -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 -- 2.45.2 From 959dc586c5d26701b2bf387657ca1e15e93c1e6a Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 17 Jan 2025 00:16:31 -0500 Subject: [PATCH 2/3] Just use solid_queue in development So you won't rip your hair out because async is thread local --- config/cable.yml | 7 ++++++- config/database.yml | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/cable.yml b/config/cable.yml index b9adc5a..7866c8d 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -3,7 +3,12 @@ # not a terminal started via bin/rails console! Add "console" to any action or any ERB template view # to make the web console appear. development: - adapter: async + adapter: solid_cable + connects_to: + database: + writing: cable + polling_interval: 0.1.seconds + message_retention: 1.day test: adapter: test diff --git a/config/database.yml b/config/database.yml index 64847cf..e1f09ac 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,6 +21,10 @@ development: <<: *default database: storage/development_queue.sqlite3 migrations_paths: db/queue_migrate + cable: + <<: *default + database: storage/development_cable.sqlite3 + migrations_paths: db/cable_migrate # Warning: The database defined as "test" will be erased and -- 2.45.2 From 84507058a6bf15c63303f8c17560ce4d23e48248 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 17 Jan 2025 00:24:29 -0500 Subject: [PATCH 3/3] Update cable_schema --- db/cable_schema.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/db/cable_schema.rb b/db/cable_schema.rb index 2366660..3aefc38 100644 --- a/db/cable_schema.rb +++ b/db/cable_schema.rb @@ -1,9 +1,21 @@ -ActiveRecord::Schema[7.1].define(version: 1) do +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.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.datetime "created_at", null: false + t.binary "payload", limit: 536870912, 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" -- 2.45.2