Skip to content

Commit

Permalink
Sidekiq -> GoodJob
Browse files Browse the repository at this point in the history
  • Loading branch information
RISCfuture committed Sep 9, 2024
1 parent e0dbd19 commit 86dc5ba
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ gem "responders"
# FRAMEWORK
gem "devise"
gem "devise-jwt"
gem "good_job"
gem "kredis"
gem "rack-cors"
gem "redis"
gem "sidekiq"

# MODELS
gem "pg"
Expand Down
21 changes: 14 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,26 @@ GEM
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
factory_bot (6.4.6)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
ffaker (2.23.0)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
good_job (4.2.1)
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.1.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -180,6 +192,7 @@ GEM
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.7)
rack-cors (2.0.2)
Expand Down Expand Up @@ -257,12 +270,6 @@ GEM
rspec-support (~> 3.13)
rspec-support (3.13.1)
securerandom (0.3.1)
sidekiq (7.3.1)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
logger
rack (>= 2.2.4)
redis-client (>= 0.22.2)
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.2)
Expand Down Expand Up @@ -304,6 +311,7 @@ DEPENDENCIES
dockerfile-rails
factory_bot_rails
ffaker
good_job
jbuilder
json_expressions
kredis
Expand All @@ -316,7 +324,6 @@ DEPENDENCIES
redis
responders
rspec-rails
sidekiq
webmock
yard

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ such as:
```
backend: cd Backend && rvm 3.3.4@flyweight exec rails server
frontend: cd Frontend && yarn dev
jobs: cd Backend && rvm 3.3.4@flyweight exec bundle exec sidekiq -C config/sidekiq.yml
jobs: cd Backend && rvm 3.3.4@flyweight exec bundle exec good_job start
cable: cd Backend && rvm 3.3.4@flyweight exec ./bin/cable
```

Expand Down
15 changes: 13 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@ class Application < Rails::Application
# Skip views, helpers and assets when generating a new resource.
config.api_only = true

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :sidekiq
config.active_job.queue_adapter = :good_job
config.active_job.queue_name_prefix = "flyweight_#{Rails.env}"
config.active_job.queue_adapter = :good_job
config.good_job.max_threads = 2
config.good_job.poll_interval = 30 # seconds
config.good_job.enable_cron = true
config.good_job.dashboard_default_locale = :en
config.good_job.queues = "flyweight_#{Rails.env}_default"

# for GoodJob dashboard
config.middleware.use Rack::MethodOverride
config.middleware.use ActionDispatch::Flash
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore

config.generators do |g|
g.test_framework :rspec, fixture: true, views: false
Expand Down
2 changes: 2 additions & 0 deletions config/environments/cypress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.good_job.poll_interval = 1
end
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
get "__cypress__/last_email" => Cypress::LastEmail.new
end

if Rails.env.production?
authenticate :pilot, -> { _1.admin? } do
mount GoodJob::Engine => "good_job"
end
else
mount GoodJob::Engine => "good_job"
end

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
Expand Down
7 changes: 0 additions & 7 deletions config/sidekiq-cypress.yml

This file was deleted.

102 changes: 102 additions & 0 deletions db/migrate/20240903015857_create_good_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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
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, %i[queue_name scheduled_at], where: "(finished_at IS NULL)", name: :index_good_jobs_on_queue_name_and_scheduled_at
add_index :good_jobs, %i[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, %i[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, %i[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, %i[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, %i[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, %i[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, %i[batch_id], where: "batch_id IS NOT NULL"
add_index :good_jobs, %i[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, %i[active_job_id created_at], name: :index_good_job_executions_on_active_job_id_and_created_at
add_index :good_jobs, %i[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, %i[process_id created_at], name: :index_good_job_executions_on_process_id_and_created_at
end
end
7 changes: 7 additions & 0 deletions db/migrate/20240903015959_add_admin_to_pilots.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddAdminToPilots < ActiveRecord::Migration[7.2]
def change
add_column :pilots, :admin, :boolean, default: false, null: false
end
end
91 changes: 90 additions & 1 deletion db/schema.rb

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

2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ console_command = '/rails/bin/rails console'

[processes]
app = './bin/rails server'
sidekiq = 'bundle exec sidekiq'
good_job = 'bundle exec good_job start'

[http_service]
internal_port = 3000
Expand Down

0 comments on commit 86dc5ba

Please sign in to comment.