Skip to content

Commit

Permalink
Convert GoodJob into a single mountable engine (instead of a plugin p…
Browse files Browse the repository at this point in the history
…lus optional engine)
  • Loading branch information
bensheldon committed Apr 5, 2022
1 parent 4b2332a commit 087ae73
Show file tree
Hide file tree
Showing 54 changed files with 31 additions and 39 deletions.
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,19 +323,6 @@ _🚧 GoodJob's dashboard is a work in progress. Please contribute ideas and cod
GoodJob includes a Dashboard as a mountable `Rails::Engine`.
1. Explicitly require the Engine code at the top of your `config/application.rb` file, immediately after Rails is required and before Bundler requires the Rails' groups. This is necessary because the mountable engine is an optional feature of GoodJob.
```ruby
# config/application.rb
require_relative 'boot'
require 'rails/all'
require 'good_job/engine' # <= Add this line
# ...
```
Note: If you find the dashboard fails to reload due to a routing error and uninitialized constant `GoodJob::ExecutionsController`, this is likely because you are not requiring the engine early enough.
1. Mount the engine in your `config/routes.rb` file. The following will mount it at `http://example.com/good_job`.
```ruby
Expand All @@ -344,7 +331,7 @@ GoodJob includes a Dashboard as a mountable `Rails::Engine`.
mount GoodJob::Engine => 'good_job'
```
Because jobs can potentially contain sensitive information, you should authorize access. For example, using Devise's `authenticate` helper, that might look like:
1. Configure authentication. Because jobs can potentially contain sensitive information, you should authorize access. For example, using Devise's `authenticate` helper, that might look like:
```ruby
# config/routes.rb
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def table_name=(_value)
self.primary_key = 'active_job_id'
self.advisory_lockable_column = 'active_job_id'

has_many :executions, -> { order(created_at: :asc) }, class_name: 'GoodJob::Execution', foreign_key: 'active_job_id', inverse_of: :job
has_many :executions, -> { order(created_at: :asc) }, class_name: 'GoodJob::Execution', foreign_key: 'active_job_id', inverse_of: :job # rubocop:disable Rails/HasManyOrHasOneDependent

# Only the most-recent unretried execution represents a "Job"
default_scope { where(retried_good_job_id: nil) }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ FileUtils.chdir GEM_ROOT do
# Must run twice to run all linters
# https://github.com/Shopify/erb-lint/issues/145
puts "Running ERB Lint with autocorrectable linters"
system!("bundle exec erblint --autocorrect engine/app/views")
system!("bundle exec erblint --autocorrect app/views")

puts "\nRunning ERB Lint with all linters"
system!("bundle exec erblint engine/app/views")
system!("bundle exec erblint app/views")
end

puts "\n== Markdown Lint =="
Expand Down
17 changes: 14 additions & 3 deletions bin/test_app
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../spec/test_app/config/application', __dir__)
require_relative '../spec/test_app/config/boot'
require 'rails/commands'
#
# Note: this command cannot be named "rails" because it will break generator specs with the message:
# "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first."

ENGINE_ROOT = File.expand_path("..", __dir__)
ENGINE_PATH = File.expand_path("../lib/good_job/engine", __dir__)
APP_PATH = File.expand_path("../spec/test_app/config/application", __dir__)

# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])

require "rails/all"
require "rails/engine/commands"
5 changes: 0 additions & 5 deletions bin/test_app_rake

This file was deleted.

File renamed without changes.
6 changes: 0 additions & 6 deletions engine/lib/good_job/engine.rb

This file was deleted.

3 changes: 2 additions & 1 deletion good_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Gem::Specification.new do |spec|
}

spec.files = Dir[
"engine/**/*",
"app/**/*",
"config/**/*",
"lib/**/*",
"README.md",
"CHANGELOG.md",
Expand Down
6 changes: 2 additions & 4 deletions lib/good_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# frozen_string_literal: true
require "rails"
require "active_job"
require "active_job/queue_adapters"

require "zeitwerk"
Zeitwerk::Loader.for_gem.tap do |loader|
Expand All @@ -12,7 +9,8 @@
loader.setup
end

require "good_job/railtie"
require "good_job/version"
require "good_job/engine"

# GoodJob is a multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails.
#
Expand Down
9 changes: 8 additions & 1 deletion lib/good_job/railtie.rb → lib/good_job/engine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# frozen_string_literal: true

require "rails"
require "active_job"
require "active_job/queue_adapters"

module GoodJob
# Ruby on Rails integration.
class Railtie < ::Rails::Railtie
class Engine < ::Rails::Engine
isolate_namespace GoodJob

config.good_job = ActiveSupport::OrderedOptions.new
config.good_job.cron = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe GoodJob::Railtie do
RSpec.describe GoodJob::Engine do
it 'copies over the Rails logger by default' do
expect(GoodJob.logger).to eq Rails.logger
end
Expand Down
1 change: 0 additions & 1 deletion spec/test_app/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative 'boot'

require 'rails/all'
require "good_job/engine"

Bundler.require(*Rails.groups)
require "good_job"
Expand Down

0 comments on commit 087ae73

Please sign in to comment.