Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert GoodJob into a single mountable engine (instead of a plugin plus optional engine) #554

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,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 @@ -353,7 +340,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.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ActiveJobJob < BaseRecord
DiscardJobError = Class.new(StandardError)

class << self
delegate :table_name, to: Execution
delegate :table_name, to: GoodJob::Execution

def table_name=(_value)
raise NotImplementedError, 'Assign GoodJob::Execution.table_name directly'
Expand All @@ -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.
6 changes: 3 additions & 3 deletions bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ FileUtils.chdir GEM_ROOT do

puts "\n== ERB Lint =="
if options[:nofix]
system!("bundle exec erblint engine/app/views")
system!("bundle exec erblint app/views")
else
# 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
13 changes: 10 additions & 3 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/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'
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"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
12 changes: 6 additions & 6 deletions i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ base_locale: en
# Read and write translations.
data:
read:
- engine/config/locales/%{locale}.yml
- engine/config/locales/**/*.%{locale}.yml
- config/locales/%{locale}.yml
- config/locales/**/*.%{locale}.yml

# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
Expand Down Expand Up @@ -46,11 +46,11 @@ data:
# Find translate calls
search:
paths:
- engine/app
- app
relative_roots:
- engine/app/controllers
- engine/app/helpers
- engine/app/views
- app/controllers
- app/helpers
- app/views

## Directories where method names which should not be part of a relative key resolution.
# By default, if a relative translation is used inside a method, the name of the method will be considered part of the resolved key.
Expand Down
3 changes: 1 addition & 2 deletions lib/good_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
require "rails"
require "active_job"
require "active_job/queue_adapters"

Expand All @@ -13,7 +12,7 @@
loader.setup
end

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

# GoodJob is a multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails.
#
Expand Down
4 changes: 3 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,9 @@
# frozen_string_literal: true
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