migrate to good job for redis removal from stack

This commit is contained in:
Chris
2025-08-09 11:58:15 -07:00
parent 2ef834cb34
commit d878056e1a
12 changed files with 252 additions and 48 deletions
+1 -4
View File
@@ -74,9 +74,8 @@ gem "noticed", "~> 2.7"
gem "omniauth-github", "~> 2.0"
gem "pretender", "~> 0.3.4"
gem "pundit", "~> 2.5"
gem "sidekiq", "~> 6.2"
gem "good_job", "~> 4.0"
gem "sitemap_generator", "~> 6.1"
gem "whenever", require: false
gem "responders", github: "heartcombo/responders", branch: "main"
gem "dotenv", "~> 3.1"
gem "image_processing", "~> 1.13"
@@ -110,8 +109,6 @@ gem "cron2english", "~> 0.1.7"
gem "avo", "~> 3.17"
gem "sidekiq-scheduler", "~> 5.0"
gem "sentry-ruby", "~> 5.23"
gem "sentry-rails", "~> 5.23"
+9 -17
View File
@@ -131,7 +131,6 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
chronic (0.10.2)
chunky_png (1.4.0)
coderay (1.1.3)
concurrent-ruby (1.3.5)
@@ -188,7 +187,7 @@ GEM
zeitwerk (~> 2.6)
erb (5.0.1)
erubi (1.13.1)
et-orbi (1.2.11)
et-orbi (1.3.0)
tzinfo
excon (0.111.0)
factory_bot (6.5.0)
@@ -220,6 +219,13 @@ GEM
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
good_job (4.11.2)
activejob (>= 6.1.0)
activerecord (>= 6.1.0)
concurrent-ruby (>= 1.3.1)
fugit (>= 1.11.0)
railties (>= 6.1.0)
thor (>= 1.0.0)
hashdiff (1.0.1)
hashie (5.0.0)
http (5.2.0)
@@ -509,8 +515,6 @@ GEM
ffi (~> 1.12)
logger
rubyzip (2.4.1)
rufus-scheduler (3.9.2)
fugit (~> 1.1, >= 1.11.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
@@ -537,14 +541,6 @@ GEM
concurrent-ruby (~> 1.0, >= 1.0.2)
shoulda-matchers (6.4.0)
activesupport (>= 5.2.0)
sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.5.0, < 5)
sidekiq-scheduler (5.0.6)
rufus-scheduler (~> 3.2)
sidekiq (>= 6, < 8)
tilt (>= 1.4.0, < 3)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
@@ -615,8 +611,6 @@ GEM
base64
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
xpath (3.2.0)
nokogiri (~> 1.8)
yajl-ruby (1.4.3)
@@ -646,6 +640,7 @@ DEPENDENCIES
factory_bot_rails
faker (~> 3.5.1)
friendly_id (~> 5.4)
good_job (~> 4.0)
httparty (~> 0.22.0)
image_processing (~> 1.13)
importmap-rails
@@ -683,8 +678,6 @@ DEPENDENCIES
sentry-rails (~> 5.23)
sentry-ruby (~> 5.23)
shoulda-matchers (~> 6.0)
sidekiq (~> 6.2)
sidekiq-scheduler (~> 5.0)
simplecov
sitemap_generator (~> 6.1)
sprockets-rails
@@ -695,7 +688,6 @@ DEPENDENCIES
tzinfo-data
web-console
webmock
whenever
BUNDLED WITH
2.5.20
+1 -1
View File
@@ -1,2 +1,2 @@
web: bin/rails server
worker: bundle exec sidekiq
worker: bundle exec good_job start
+1 -1
View File
@@ -1,4 +1,4 @@
web: bin/rails server -p ${PORT:-3000}
worker: bundle exec sidekiq
worker: bundle exec good_job start
js: yarn build --watch
css: bin/rails tailwindcss:watch
+1 -1
View File
@@ -1,5 +1,5 @@
class ApplicationJob < ActiveJob::Base
sidekiq_options retry: false
retry_on StandardError, attempts: 0
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
+2 -2
View File
@@ -32,9 +32,9 @@
</li>
<li>
<div>
<%= link_to admin_sidekiq_web_path do %>
<%= link_to admin_good_job_path do %>
<iconify-icon icon="lucide:server" height="16"></iconify-icon>
Sidekiq
Jobs
<% end %>
</div>
</li>
+1 -1
View File
@@ -10,7 +10,7 @@ module Canine
class Application < Rails::Application
config.assets.css_compressor = nil
config.local_mode = ENV["LOCAL_MODE"] == "true"
config.active_job.queue_adapter = :sidekiq
config.active_job.queue_adapter = :good_job
config.application_name = Rails.application.class.module_parent_name
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.2
+40
View File
@@ -0,0 +1,40 @@
Rails.application.configure do
config.good_job = {
preserve_job_records: true,
retry_on_unhandled_error: false,
on_thread_error: ->(exception) { Rails.logger.error(exception) },
execution_mode: :external,
queues: '*',
max_threads: 5,
poll_interval: 30,
shutdown_timeout: 25,
enable_cron: true,
cron: {
check_health: {
cron: "*/15 * * * *",
class: "Scheduled::CheckHealthJob",
description: "Check service health every 15 minutes"
},
fetch_metrics: {
cron: "*/15 * * * *",
class: "Scheduled::FetchMetricsJob",
description: "Fetch metrics every 15 minutes"
},
flush_metrics: {
cron: "0 0 * * *",
class: "Scheduled::FlushMetricsJob",
description: "Flush metrics daily at midnight"
},
cancel_hanging_builds: {
cron: "0 * * * *",
class: "Scheduled::CancelHangingBuildsJob",
description: "Cancel hanging builds every hour"
},
cleanup_closed_pr_projects: {
cron: "*/30 * * * *",
class: "CleanupClosedPrProjectsJob",
description: "Cleanup closed PR projects every 30 minutes"
}
}
}
end
+1 -3
View File
@@ -1,5 +1,3 @@
require "sidekiq/web"
Rails.application.routes.draw do
authenticate :user, ->(user) { user.admin? } do
mount Avo::Engine, at: Avo.configuration.root_path
@@ -92,7 +90,7 @@ Rails.application.routes.draw do
authenticate :user, lambda { |u| u.admin? } do
namespace :admin do
mount Sidekiq::Web => "/sidekiq"
mount GoodJob::Engine => "/good_job"
end
end
-17
View File
@@ -1,17 +0,0 @@
:scheduler:
:schedule:
check_health_job:
every: '15m'
class: Scheduled::CheckHealthJob
fetch_metrics_job:
every: '15m'
class: Scheduled::FetchMetricsJob
flush_metrics_job:
every: '1d'
class: Scheduled::FlushMetricsJob
cancel_hanging_builds_job:
every: '1h'
class: Scheduled::CancelHangingBuildsJob
cleanup_closed_pr_projects_job:
every: '30m'
class: CleanupClosedPrProjectsJob
@@ -0,0 +1,104 @@
# frozen_string_literal: true
class CreateGoodJobs < ActiveRecord::Migration[7.2]
def change
# Uncomment for Postgres v12 or earlier to enable gen_random_uuid() support
# enable_extension 'pgcrypto'
create_table :good_jobs, id: :uuid do |t|
t.text :queue_name
t.integer :priority
t.jsonb :serialized_params
t.datetime :scheduled_at
t.datetime :performed_at
t.datetime :finished_at
t.text :error
t.timestamps
t.uuid :active_job_id
t.text :concurrency_key
t.text :cron_key
t.uuid :retried_good_job_id
t.datetime :cron_at
t.uuid :batch_id
t.uuid :batch_callback_id
t.boolean :is_discrete
t.integer :executions_count
t.text :job_class
t.integer :error_event, limit: 2
t.text :labels, array: true
t.uuid :locked_by_id
t.datetime :locked_at
end
create_table :good_job_batches, id: :uuid do |t|
t.timestamps
t.text :description
t.jsonb :serialized_properties
t.text :on_finish
t.text :on_success
t.text :on_discard
t.text :callback_queue_name
t.integer :callback_priority
t.datetime :enqueued_at
t.datetime :discarded_at
t.datetime :finished_at
t.datetime :jobs_finished_at
end
create_table :good_job_executions, id: :uuid do |t|
t.timestamps
t.uuid :active_job_id, null: false
t.text :job_class
t.text :queue_name
t.jsonb :serialized_params
t.datetime :scheduled_at
t.datetime :finished_at
t.text :error
t.integer :error_event, limit: 2
t.text :error_backtrace, array: true
t.uuid :process_id
t.interval :duration
end
create_table :good_job_processes, id: :uuid do |t|
t.timestamps
t.jsonb :state
t.integer :lock_type, limit: 2
end
create_table :good_job_settings, id: :uuid do |t|
t.timestamps
t.text :key
t.jsonb :value
t.index :key, unique: true
end
add_index :good_jobs, :scheduled_at, where: "(finished_at IS NULL)", name: :index_good_jobs_on_scheduled_at
add_index :good_jobs, [ :queue_name, :scheduled_at ], where: "(finished_at IS NULL)", name: :index_good_jobs_on_queue_name_and_scheduled_at
add_index :good_jobs, [ :active_job_id, :created_at ], name: :index_good_jobs_on_active_job_id_and_created_at
add_index :good_jobs, :concurrency_key, where: "(finished_at IS NULL)", name: :index_good_jobs_on_concurrency_key_when_unfinished
add_index :good_jobs, [ :concurrency_key, :created_at ], name: :index_good_jobs_on_concurrency_key_and_created_at
add_index :good_jobs, [ :cron_key, :created_at ], where: "(cron_key IS NOT NULL)", name: :index_good_jobs_on_cron_key_and_created_at_cond
add_index :good_jobs, [ :cron_key, :cron_at ], where: "(cron_key IS NOT NULL)", unique: true, name: :index_good_jobs_on_cron_key_and_cron_at_cond
add_index :good_jobs, [ :finished_at ], where: "retried_good_job_id IS NULL AND finished_at IS NOT NULL", name: :index_good_jobs_jobs_on_finished_at
add_index :good_jobs, [ :priority, :created_at ], order: { priority: "DESC NULLS LAST", created_at: :asc },
where: "finished_at IS NULL", name: :index_good_jobs_jobs_on_priority_created_at_when_unfinished
add_index :good_jobs, [ :priority, :created_at ], order: { priority: "ASC NULLS LAST", created_at: :asc },
where: "finished_at IS NULL", name: :index_good_job_jobs_for_candidate_lookup
add_index :good_jobs, [ :batch_id ], where: "batch_id IS NOT NULL"
add_index :good_jobs, [ :batch_callback_id ], where: "batch_callback_id IS NOT NULL"
add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)", name: :index_good_jobs_on_labels
add_index :good_job_executions, [ :active_job_id, :created_at ], name: :index_good_job_executions_on_active_job_id_and_created_at
add_index :good_jobs, [ :priority, :scheduled_at ], order: { priority: "ASC NULLS LAST", scheduled_at: :asc },
where: "finished_at IS NULL AND locked_by_id IS NULL", name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked
add_index :good_jobs, :locked_by_id,
where: "locked_by_id IS NOT NULL", name: "index_good_jobs_on_locked_by_id"
add_index :good_job_executions, [ :process_id, :created_at ], name: :index_good_job_executions_on_process_id_and_created_at
end
end
Generated
+91 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2025_07_29_215525) do
ActiveRecord::Schema[7.2].define(version: 2025_08_09_185224) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -163,6 +163,96 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_29_215525) do
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
end
create_table "good_job_batches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description"
t.jsonb "serialized_properties"
t.text "on_finish"
t.text "on_success"
t.text "on_discard"
t.text "callback_queue_name"
t.integer "callback_priority"
t.datetime "enqueued_at"
t.datetime "discarded_at"
t.datetime "finished_at"
t.datetime "jobs_finished_at"
end
create_table "good_job_executions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "active_job_id", null: false
t.text "job_class"
t.text "queue_name"
t.jsonb "serialized_params"
t.datetime "scheduled_at"
t.datetime "finished_at"
t.text "error"
t.integer "error_event", limit: 2
t.text "error_backtrace", array: true
t.uuid "process_id"
t.interval "duration"
t.index ["active_job_id", "created_at"], name: "index_good_job_executions_on_active_job_id_and_created_at"
t.index ["process_id", "created_at"], name: "index_good_job_executions_on_process_id_and_created_at"
end
create_table "good_job_processes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.jsonb "state"
t.integer "lock_type", limit: 2
end
create_table "good_job_settings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "key"
t.jsonb "value"
t.index ["key"], name: "index_good_job_settings_on_key", unique: true
end
create_table "good_jobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.text "queue_name"
t.integer "priority"
t.jsonb "serialized_params"
t.datetime "scheduled_at"
t.datetime "performed_at"
t.datetime "finished_at"
t.text "error"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "active_job_id"
t.text "concurrency_key"
t.text "cron_key"
t.uuid "retried_good_job_id"
t.datetime "cron_at"
t.uuid "batch_id"
t.uuid "batch_callback_id"
t.boolean "is_discrete"
t.integer "executions_count"
t.text "job_class"
t.integer "error_event", limit: 2
t.text "labels", array: true
t.uuid "locked_by_id"
t.datetime "locked_at"
t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at"
t.index ["batch_callback_id"], name: "index_good_jobs_on_batch_callback_id", where: "(batch_callback_id IS NOT NULL)"
t.index ["batch_id"], name: "index_good_jobs_on_batch_id", where: "(batch_id IS NOT NULL)"
t.index ["concurrency_key", "created_at"], name: "index_good_jobs_on_concurrency_key_and_created_at"
t.index ["concurrency_key"], name: "index_good_jobs_on_concurrency_key_when_unfinished", where: "(finished_at IS NULL)"
t.index ["cron_key", "created_at"], name: "index_good_jobs_on_cron_key_and_created_at_cond", where: "(cron_key IS NOT NULL)"
t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at_cond", unique: true, where: "(cron_key IS NOT NULL)"
t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))"
t.index ["labels"], name: "index_good_jobs_on_labels", where: "(labels IS NOT NULL)", using: :gin
t.index ["locked_by_id"], name: "index_good_jobs_on_locked_by_id", where: "(locked_by_id IS NOT NULL)"
t.index ["priority", "created_at"], name: "index_good_job_jobs_for_candidate_lookup", where: "(finished_at IS NULL)"
t.index ["priority", "created_at"], name: "index_good_jobs_jobs_on_priority_created_at_when_unfinished", order: { priority: "DESC NULLS LAST" }, where: "(finished_at IS NULL)"
t.index ["priority", "scheduled_at"], name: "index_good_jobs_on_priority_scheduled_at_unfinished_unlocked", where: "((finished_at IS NULL) AND (locked_by_id IS NULL))"
t.index ["queue_name", "scheduled_at"], name: "index_good_jobs_on_queue_name_and_scheduled_at", where: "(finished_at IS NULL)"
t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)"
end
create_table "inbound_webhooks", force: :cascade do |t|
t.text "body"
t.integer "status", default: 0