Skip to content

Commit

Permalink
Add solid cable and solid queue (#1264)
Browse files Browse the repository at this point in the history
* add solid cable

* add solid queue
  • Loading branch information
jmilljr24 authored Dec 17, 2024
1 parent e7169ff commit 76d7acf
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,7 @@ group :test do
# Adds ability to stub out methods in tests easier
gem "mocha"
end

gem "solid_cable", "~> 3.0"

gem "solid_queue", "~> 1.1"
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ GEM
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
eventmachine (1.2.7)
evil_systems (1.1.5)
capybara
Expand Down Expand Up @@ -234,6 +236,9 @@ GEM
figaro (1.2.0)
thor (>= 0.14.0, < 2)
formatador (1.1.0)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
google-protobuf (4.29.1)
Expand Down Expand Up @@ -382,6 +387,7 @@ GEM
public_suffix (6.0.1)
puma (6.5.0)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.8)
rack-session (2.0.0)
Expand Down Expand Up @@ -490,6 +496,18 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
solid_cable (3.0.4)
actioncable (>= 7.2)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_queue (1.1.0)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11.0)
railties (>= 7.1)
thor (~> 1.3.1)
sshkit (1.23.2)
base64
net-scp (>= 1.1.2)
Expand Down Expand Up @@ -603,6 +621,8 @@ DEPENDENCIES
shoulda (~> 4.0)
shoulda-matchers
simplecov
solid_cable (~> 3.0)
solid_queue (~> 1.1)
standard
stimulus-rails
strong_migrations (~> 2.1)
Expand Down
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: bin/rails server -p 3000
css: bin/rails dartsass:watch
jobs: bin/jobs
6 changes: 6 additions & 0 deletions bin/jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require_relative "../config/environment"
require "solid_queue/cli"

SolidQueue::Cli.start(ARGV)
20 changes: 16 additions & 4 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# 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
adapter: solid_cable
connects_to:
database:
writing: cable
polling_interval: 0.1.seconds
message_retention: 1.day

test:
adapter: test

production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: pet_rescue_production
adapter: solid_cable
connects_to:
database:
writing: cable
polling_interval: 0.1.seconds
message_retention: 1.day
45 changes: 33 additions & 12 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,24 @@ default: &default
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
database: pet_rescue_development
# The following line comes from:
# https://stackoverflow.com/questions/59089991/ruby-2-6-5-and-postgresql-pg-gem-segmentation-fault
gssencmode: disable
primary:
<<: *default
database: pet_rescue_development
# The following line comes from:
# https://stackoverflow.com/questions/59089991/ruby-2-6-5-and-postgresql-pg-gem-segmentation-fault
gssencmode: disable

cable:
<<: *default
database: cable
migrations_paths: db/cable_migrate
gssencmode: disable

queue:
<<: *default
database: queue
migrations_paths: db/queue_migrate
gssencmode: disable

#username: <%= ENV.fetch('DATABASE_USERNAME') { 'postgres' } %>
#password: <%= ENV.fetch('DATABASE_PASSWORD') { 'password' } %>
Expand Down Expand Up @@ -91,10 +104,18 @@ test:
# for a full overview on how database connection configuration can be specified.
#
production:
<<: *default
host: <%= ENV["DB_HOST"] %>
pool: 5
username: <%= ENV["DB_USER"] %>
password: <%= ENV["DB_PASSWORD"] %>
database: postgres
timeout: 5000
primary: &primary_production
<<: *default
host: <%= ENV["DB_HOST"] %>
username: <%= ENV["DB_USER"] %>
password: <%= ENV["DB_PASSWORD"] %>
database: postgres
timeout: 5000
cable:
<<: *primary_production
database: cable
migrations_paths: db/cable_migrate
queue:
<<: *primary_production
database: queue
migrations_paths: db/queue_migrate
9 changes: 8 additions & 1 deletion config/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ env:
- DB_HOST
- DB_USER
- DB_PASSWORD
clear:
# Run the Solid Queue Supervisor inside the web server's Puma process to do jobs.
# When you start using multiple servers, you should split out job processing to a dedicated machine.
SOLID_QUEUE_IN_PUMA: true

# Log everything from Rails
# RAILS_LOG_LEVEL: debug

# Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation:
# "bin/kamal logs -r job" will tail logs from the first server in the job section.
#
aliases:
shell: app exec --interactive --reuse "bash"
logs: app exec -i --reuse "tail -f log/production.log"
logs: app logs -f
console: app exec -i --reuse "bin/rails console"

# Use a different ssh user than root
Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@
config.app_url = "http://localhost:3000/"
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
# config.generators.apply_rubocop_autocorrect_after_generate!

config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = {database: {writing: :queue}}
end
7 changes: 2 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
config.assume_ssl = true
config.force_ssl = true

# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
config.log_level = :info
# Skip http-to-https redirect for the default health check endpoint.
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }

Expand All @@ -67,7 +64,6 @@

# Change to "debug" to log everything (including potentially personally-identifiable information!)
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")

# config.active_job.queue_name_prefix = "baja_pet_rescue_production"
# Prevent health checks from clogging up the logs.
config.silence_healthcheck_path = "/up"
Expand All @@ -83,7 +79,8 @@
# config.cache_store = :mem_cache_store

# Replace the default in-process and non-durable queuing backend for Active Job.
# config.active_job.queue_adapter = :resque
config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = {database: {writing: :queue}}
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
Expand Down
18 changes: 18 additions & 0 deletions config/queue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default: &default
dispatchers:
- polling_interval: 1
batch_size: 500
workers:
- queues: "*"
threads: 3
processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %>
polling_interval: 0.1

development:
<<: *default

test:
<<: *default

production:
<<: *default
10 changes: 10 additions & 0 deletions config/recurring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# production:
# periodic_cleanup:
# class: CleanSoftDeletedRecordsJob
# queue: background
# args: [ 1000, { batch_size: 500 } ]
# schedule: every hour
# periodic_command:
# command: "SoftDeletedRecord.due.delete_all"
# priority: 2
# schedule: at 5am every day
Empty file added db/cable_migrate/.keep
Empty file.
26 changes: 26 additions & 0 deletions db/cable_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.0].define(version: 1) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"

create_table "solid_cable_messages", force: :cascade do |t|
t.binary "channel", null: false
t.binary "payload", null: false
t.datetime "created_at", null: false
t.bigint "channel_hash", 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
Empty file added db/queue_migrate/.keep
Empty file.
Loading

0 comments on commit 76d7acf

Please sign in to comment.