Skip to content

Commit

Permalink
Setup SolidQueue on the sample app
Browse files Browse the repository at this point in the history
The sample setup helps ensure the reporting works.

We can install mission control manually if we want to inspect jobs, but
I've left it commented out because right now it relies on Rails and
sprockets and we don't really need those dependencies most of the time.
  • Loading branch information
carlosantoniodasilva committed Apr 23, 2024
1 parent 620cbaf commit 425c672
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 6 deletions.
9 changes: 7 additions & 2 deletions sample-apps/solid_queue-sample/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ gem "puma", "~> 6.0"
# but we want to test against the local dev versions of them, not the released gems.
gem "judoscale-ruby", path: "../../judoscale-ruby"
gem "judoscale-rails", path: "../../judoscale-rails"
# gem "judoscale-solid_queue", path: "../../judoscale-solid_queue"
gem "judoscale-solid_queue", path: "../../judoscale-solid_queue"

# gem "solid_queue", "~> 0.3"
gem "solid_queue", "~> 0.3"
# Install mission control to inspect jobs in the web UI.
# (A `/jobs` route is added via config/routes.rb if `MissionControl` is detected.)
# Note: mission control requires assets, so we also need sprockets-rails here for now.
# gem "mission_control-jobs"
# gem "sprockets-rails"
21 changes: 21 additions & 0 deletions sample-apps/solid_queue-sample/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ PATH
specs:
judoscale-ruby (1.5.4)

PATH
remote: ../../judoscale-solid_queue
specs:
judoscale-solid_queue (1.5.4)
judoscale-ruby (= 1.5.4)
solid_queue (>= 0.3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -56,6 +63,11 @@ GEM
crass (1.0.6)
drb (2.2.1)
erubi (1.12.0)
et-orbi (1.2.11)
tzinfo
fugit (1.9.0)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.4)
Expand All @@ -81,6 +93,7 @@ GEM
stringio
puma (6.4.2)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.7.3)
rack (3.0.10)
rack-session (2.0.0)
Expand Down Expand Up @@ -110,6 +123,12 @@ GEM
psych (>= 4.0.0)
reline (0.5.3)
io-console (~> 0.5)
solid_queue (0.3.0)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (~> 1.2.2)
fugit (~> 1.9.0)
railties (>= 7.1)
stringio (3.1.0)
thor (1.3.1)
timeout (0.4.1)
Expand All @@ -133,9 +152,11 @@ DEPENDENCIES
activerecord (~> 7.1.0)
judoscale-rails!
judoscale-ruby!
judoscale-solid_queue!
pg (~> 1.5)
puma (~> 6.0)
railties (~> 7.1.0)
solid_queue (~> 0.3)

BUNDLED WITH
2.5.4
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class JobsController < ApplicationController
def index
@available_queues = QUEUES.dup
@queues = []
# @queues = Delayed::Backend::ActiveRecord::Job.group(:queue).count
@queues = ::SolidQueue::ReadyExecution.group(:queue_name).count
end

def create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p>
Enqueue test jobs using the form below.
They will be slowly processed by SolidQueue, while Judoscale collects and reports available queue metrics.
<%= link_to "SolidQueue / MissionControl Dashboard ↗", "/mission_control", target: "_blank" %>.
<%= link_to "SolidQueue / MissionControl Dashboard ↗", "/jobs", target: "_blank" if defined?(MissionControl) %>.
</p>

<h2>SolidQueue Queues</h2>
Expand Down
2 changes: 1 addition & 1 deletion sample-apps/solid_queue-sample/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ class Application < Rails::Application
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)

# config.active_job.queue_adapter = :solid_queue
config.active_job.queue_adapter = :solid_queue
end
end
1 change: 1 addition & 0 deletions sample-apps/solid_queue-sample/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resource :jobs, only: [:index, :create]
mount MissionControl::Jobs::Engine, at: "/jobs" if defined?(MissionControl)
root "jobs#index"
end
18 changes: 18 additions & 0 deletions sample-apps/solid_queue-sample/config/solid_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: 1
# polling_interval: 0.1
#
# development:
# <<: *default
#
# test:
# <<: *default
#
# production:
# <<: *default
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This migration comes from solid_queue (originally 20231211200639)
class CreateSolidQueueTables < ActiveRecord::Migration[7.0]
def change
create_table :solid_queue_jobs do |t|
t.string :queue_name, null: false
t.string :class_name, null: false, index: true
t.text :arguments
t.integer :priority, default: 0, null: false
t.string :active_job_id, index: true
t.datetime :scheduled_at
t.datetime :finished_at, index: true
t.string :concurrency_key

t.timestamps

t.index [ :queue_name, :finished_at ], name: "index_solid_queue_jobs_for_filtering"
t.index [ :scheduled_at, :finished_at ], name: "index_solid_queue_jobs_for_alerting"
end

create_table :solid_queue_scheduled_executions do |t|
t.references :job, index: { unique: true }, null: false
t.string :queue_name, null: false
t.integer :priority, default: 0, null: false
t.datetime :scheduled_at, null: false

t.datetime :created_at, null: false

t.index [ :scheduled_at, :priority, :job_id ], name: "index_solid_queue_dispatch_all"
end

create_table :solid_queue_ready_executions do |t|
t.references :job, index: { unique: true }, null: false
t.string :queue_name, null: false
t.integer :priority, default: 0, null: false

t.datetime :created_at, null: false

t.index [ :priority, :job_id ], name: "index_solid_queue_poll_all"
t.index [ :queue_name, :priority, :job_id ], name: "index_solid_queue_poll_by_queue"
end

create_table :solid_queue_claimed_executions do |t|
t.references :job, index: { unique: true }, null: false
t.bigint :process_id
t.datetime :created_at, null: false

t.index [ :process_id, :job_id ]
end

create_table :solid_queue_blocked_executions do |t|
t.references :job, index: { unique: true }, null: false
t.string :queue_name, null: false
t.integer :priority, default: 0, null: false
t.string :concurrency_key, null: false
t.datetime :expires_at, null: false

t.datetime :created_at, null: false

t.index [ :expires_at, :concurrency_key ], name: "index_solid_queue_blocked_executions_for_maintenance"
end

create_table :solid_queue_failed_executions do |t|
t.references :job, index: { unique: true }, null: false
t.text :error
t.datetime :created_at, null: false
end

create_table :solid_queue_pauses do |t|
t.string :queue_name, null: false, index: { unique: true }
t.datetime :created_at, null: false
end

create_table :solid_queue_processes do |t|
t.string :kind, null: false
t.datetime :last_heartbeat_at, null: false, index: true
t.bigint :supervisor_id, index: true

t.integer :pid, null: false
t.string :hostname
t.text :metadata

t.datetime :created_at, null: false
end

create_table :solid_queue_semaphores do |t|
t.string :key, null: false, index: { unique: true }
t.integer :value, default: 1, null: false
t.datetime :expires_at, null: false, index: true

t.timestamps

t.index [ :key, :value ], name: "index_solid_queue_semaphores_on_key_and_value"
end

add_foreign_key :solid_queue_blocked_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
add_foreign_key :solid_queue_claimed_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
add_foreign_key :solid_queue_failed_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
add_foreign_key :solid_queue_ready_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
add_foreign_key :solid_queue_scheduled_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This migration comes from solid_queue (originally 20240110143450)
class AddMissingIndexToBlockedExecutions < ActiveRecord::Migration[7.1]
def change
add_index :solid_queue_blocked_executions, [ :concurrency_key, :priority, :job_id ], name: "index_solid_queue_blocked_executions_for_release"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This migration comes from solid_queue (originally 20240218110712)
class CreateRecurringExecutions < ActiveRecord::Migration[7.1]
def change
create_table :solid_queue_recurring_executions do |t|
t.references :job, index: { unique: true }, null: false
t.string :task_key, null: false
t.datetime :run_at, null: false
t.datetime :created_at, null: false

t.index [ :task_key, :run_at ], unique: true
end

add_foreign_key :solid_queue_recurring_executions, :solid_queue_jobs, column: :job_id, on_delete: :cascade
end
end
119 changes: 118 additions & 1 deletion sample-apps/solid_queue-sample/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 425c672

Please sign in to comment.