good_job 2.9.0 → 2.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba4a26a2047c0e7dd8b78264fee7c6d2c05c2dd59e38f1df402b698826b56288
4
- data.tar.gz: 3bd4c49139941c2d37751abb9d32808b0efd7a33370aa7370afeed21cc845ab0
3
+ metadata.gz: b97fd131b5bf8c808b9b40b42e0daad06c3e657e9f9f093bda45ef7b1ad003cd
4
+ data.tar.gz: 4b988574b3e6c5d6877f835c7b9a2956099737a508b824da53e3e61005f4fcc7
5
5
  SHA512:
6
- metadata.gz: d2ade6a5c9b26e1d9d1bc1522dc10159f78943b5da249effa1405dccf5c3de5078f74a08c27657eef63d51967bb04eb8486d933e9d817664a25c33f3740f2280
7
- data.tar.gz: 40dc9f0b3b1d210ddcec9d7ce5dd7014e2409d5602bb4b3c55314b5bf799ef29fab9fd0764931c2026242c91383a335b64c4f3243ea16d50997e59ef9c7820e3
6
+ metadata.gz: caf7be40dd4b22cd6461e5dc8f83349ea377cdf7edfd0082d85ec35a9636ee58d1e4d890ba7d6aae9cb81e1357c1e3d709501ff68d173f3443d399903f4185ac
7
+ data.tar.gz: 913bcd9082c2a66d48e85af5d8f8bab86fdf355636a59fe1a4328f77f0fc952b13ee722d9b867238bd4da6dd3301820f2f5dd1407758f7cf23ec7152edd149f7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,66 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.9.4](https://github.com/bensheldon/good_job/tree/v2.9.4) (2022-01-31)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.9.3...v2.9.4)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Fix navbar toggler [\#506](https://github.com/bensheldon/good_job/pull/506) ([JuanVqz](https://github.com/JuanVqz))
10
+ - Guard LogSubscriber against tagged logger without a formatter [\#504](https://github.com/bensheldon/good_job/pull/504) ([bensheldon](https://github.com/bensheldon))
11
+ - Markdown lint fixes + Added missing responsive meta tag [\#492](https://github.com/bensheldon/good_job/pull/492) ([zeevy](https://github.com/zeevy))
12
+
13
+ **Closed issues:**
14
+
15
+ - The navbar icon doesn't show the navbar menu when clicking it [\#503](https://github.com/bensheldon/good_job/issues/503)
16
+ - Not all loggers have a formatter [\#502](https://github.com/bensheldon/good_job/issues/502)
17
+ - Error logs from failed jobs used all storage space [\#495](https://github.com/bensheldon/good_job/issues/495)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Update Code of Conduct to Contributor Covenant 2.1 [\#501](https://github.com/bensheldon/good_job/pull/501) ([bensheldon](https://github.com/bensheldon))
22
+ - Test with Ruby 3.1 [\#498](https://github.com/bensheldon/good_job/pull/498) ([aried3r](https://github.com/aried3r))
23
+
24
+ ## [v2.9.3](https://github.com/bensheldon/good_job/tree/v2.9.3) (2022-01-23)
25
+
26
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.9.2...v2.9.3)
27
+
28
+ **Fixed bugs:**
29
+
30
+ - Use `*_url` route helpers for Dashboard assets to avoid being overridden by `config.asset_host` [\#493](https://github.com/bensheldon/good_job/pull/493) ([bensheldon](https://github.com/bensheldon))
31
+
32
+ **Closed issues:**
33
+
34
+ - Assets not loaded when Rails is configured with a different hostname for assets [\#491](https://github.com/bensheldon/good_job/issues/491)
35
+
36
+ ## [v2.9.2](https://github.com/bensheldon/good_job/tree/v2.9.2) (2022-01-19)
37
+
38
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.9.1...v2.9.2)
39
+
40
+ **Fixed bugs:**
41
+
42
+ - Error on GJ admin UI search form [\#487](https://github.com/bensheldon/good_job/issues/487)
43
+ - Use `websearch_to_tsquery` or \(`plainto_tsquery` for Postgres \< v11\) for Dashboard search filter [\#488](https://github.com/bensheldon/good_job/pull/488) ([bensheldon](https://github.com/bensheldon))
44
+
45
+ **Merged pull requests:**
46
+
47
+ - Update README to illustrate using named arguments for the unique key. [\#486](https://github.com/bensheldon/good_job/pull/486) ([phallstrom](https://github.com/phallstrom))
48
+ - Add details about exactly where to require the engine. [\#485](https://github.com/bensheldon/good_job/pull/485) ([phallstrom](https://github.com/phallstrom))
49
+ - $ symbol gets copied when clicking on the copy button [\#484](https://github.com/bensheldon/good_job/pull/484) ([zeevy](https://github.com/zeevy))
50
+
51
+ ## [v2.9.1](https://github.com/bensheldon/good_job/tree/v2.9.1) (2022-01-13)
52
+
53
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.9.0...v2.9.1)
54
+
55
+ **Fixed bugs:**
56
+
57
+ - Start async adapters once `ActiveRecord` and `ActiveJob` have loaded, potentially before `Rails.application.initialized?` [\#483](https://github.com/bensheldon/good_job/pull/483) ([bensheldon](https://github.com/bensheldon))
58
+
59
+ **Closed issues:**
60
+
61
+ - Graceful fallback to polling when LISTEN/NOTIFY isn't available [\#482](https://github.com/bensheldon/good_job/issues/482)
62
+ - Long running locks on latest good job [\#480](https://github.com/bensheldon/good_job/issues/480)
63
+
3
64
  ## [v2.9.0](https://github.com/bensheldon/good_job/tree/v2.9.0) (2022-01-09)
4
65
 
5
66
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.8.1...v2.9.0)
data/README.md CHANGED
@@ -73,19 +73,19 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
73
73
  1. Install the gem:
74
74
 
75
75
  ```bash
76
- $ bundle install
76
+ bundle install
77
77
  ```
78
78
 
79
79
  1. Run the GoodJob install generator. This will generate a database migration to create a table for GoodJob's job records:
80
80
 
81
81
  ```bash
82
- $ bin/rails g good_job:install
82
+ bin/rails g good_job:install
83
83
  ```
84
84
 
85
85
  Run the migration:
86
86
 
87
87
  ```bash
88
- $ bin/rails db:migrate
88
+ bin/rails db:migrate
89
89
  ```
90
90
 
91
91
  Optional: If using Rails' multiple databases with the `migrations_paths` configuration option, use the `--database` option:
@@ -119,7 +119,7 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
119
119
  - By default, GoodJob separates job enqueuing from job execution so that jobs can be scaled independently of the web server. Use the GoodJob command-line tool to execute jobs:
120
120
 
121
121
  ```bash
122
- $ bundle exec good_job start
122
+ bundle exec good_job start
123
123
  ```
124
124
 
125
125
  Ideally the command-line tool should be run on a separate machine or container from the web process. For example, on Heroku:
@@ -133,8 +133,8 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
133
133
 
134
134
  - GoodJob can also be configured to execute jobs within the web server process to save on resources. This is useful for low-workloads when economy is paramount.
135
135
 
136
- ```
137
- $ GOOD_JOB_EXECUTION_MODE=async rails server
136
+ ```bash
137
+ GOOD_JOB_EXECUTION_MODE=async rails server
138
138
  ```
139
139
 
140
140
  Additional configuration is likely necessary, see the reference below for configuration.
@@ -142,7 +142,7 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
142
142
  ## Compatibility
143
143
 
144
144
  - **Ruby on Rails:** 5.2+
145
- - **Ruby:** MRI 2.5+. JRuby 9.2.13+ (_JRuby's `activerecord-jdbcpostgresql-adapter` gem does not support Postgres LISTEN/NOTIFY)._
145
+ - **Ruby:** MRI 2.5+. JRuby 9.2.13+
146
146
  - **Postgres:** 9.6+
147
147
 
148
148
  ## Configuration
@@ -328,7 +328,7 @@ _🚧 GoodJob's dashboard is a work in progress. Please contribute ideas and cod
328
328
 
329
329
  GoodJob includes a Dashboard as a mountable `Rails::Engine`.
330
330
 
331
- 1. Explicitly require the Engine code at the top of your `config/application.rb` file, immediately after Rails is required. This is necessary because the mountable engine is an optional feature of GoodJob.
331
+ 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.
332
332
 
333
333
  ```ruby
334
334
  # config/application.rb
@@ -339,6 +339,8 @@ GoodJob includes a Dashboard as a mountable `Rails::Engine`.
339
339
  # ...
340
340
  ```
341
341
 
342
+ 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.
343
+
342
344
  1. Mount the engine in your `config/routes.rb` file. The following will mount it at `http://example.com/good_job`.
343
345
 
344
346
  ```ruby
@@ -399,6 +401,9 @@ class MyJob < ApplicationJob
399
401
  # Can be String or Lambda/Proc that is invoked in the context of the job.
400
402
  # Note: Arguments passed to #perform_later must be accessed through `arguments` method.
401
403
  key: -> { "Unique-#{arguments.first}" } # MyJob.perform_later("Alice") => "Unique-Alice"
404
+
405
+ # If the method uses named parameters, they can be accessed like so:
406
+ # key: -> { "Unique-#{arguments.first['name']}" } # MyJob.perform_later(name: "Alice")
402
407
  )
403
408
 
404
409
  def perform(first_name)
@@ -465,7 +470,7 @@ To perform upgrades to the GoodJob database tables:
465
470
  Optional: If using Rails' multiple databases with the `migrations_paths` configuration option, use the `--database` option:
466
471
 
467
472
  ```bash
468
- $ bin/rails g good_job:update --database animals
473
+ bin/rails g good_job:update --database animals
469
474
  ```
470
475
 
471
476
  1. Run the database migration locally
@@ -698,7 +703,7 @@ GoodJob can execute jobs "async" in the same process as the web server (e.g. `bi
698
703
  - Or, with environment variables:
699
704
 
700
705
  ```bash
701
- $ GOOD_JOB_EXECUTION_MODE=async GOOD_JOB_MAX_THREADS=4 GOOD_JOB_POLL_INTERVAL=30 bin/rails server
706
+ GOOD_JOB_EXECUTION_MODE=async GOOD_JOB_MAX_THREADS=4 GOOD_JOB_POLL_INTERVAL=30 bin/rails server
702
707
  ```
703
708
 
704
709
  Depending on your application configuration, you may need to take additional steps:
@@ -816,7 +821,7 @@ It is also necessary to delete these preserved jobs from the database after a ce
816
821
  - For example, using the `good_job` command-line utility:
817
822
 
818
823
  ```bash
819
- $ bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400
824
+ bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400
820
825
  ```
821
826
 
822
827
  ### PgBouncer compatibility
@@ -2,23 +2,26 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <title>Good Job Dashboard</title>
5
+ <meta charset="utf-8">
6
+ <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
5
7
  <%= csrf_meta_tags %>
6
8
  <%= csp_meta_tag %>
7
9
 
8
- <%= stylesheet_link_tag bootstrap_path(format: :css, v: GoodJob::VERSION) %>
9
- <%= stylesheet_link_tag style_path(format: :css, v: GoodJob::VERSION) %>
10
+ <%# Assets must use *_url route helpers to avoid being overriden by config.asset_host %>
11
+ <%= stylesheet_link_tag bootstrap_url(format: :css, v: GoodJob::VERSION), skip_pipeline: true %>
12
+ <%= stylesheet_link_tag style_url(format: :css, v: GoodJob::VERSION) %>
10
13
 
11
- <%= javascript_include_tag bootstrap_path(format: :js, v: GoodJob::VERSION), nonce: true %>
12
- <%= javascript_include_tag chartjs_path(format: :js, v: GoodJob::VERSION), nonce: true %>
13
- <%= javascript_include_tag scripts_path(format: :js, v: GoodJob::VERSION), nonce: true %>
14
+ <%= javascript_include_tag bootstrap_url(format: :js, v: GoodJob::VERSION), nonce: true %>
15
+ <%= javascript_include_tag chartjs_url(format: :js, v: GoodJob::VERSION), nonce: true %>
16
+ <%= javascript_include_tag scripts_url(format: :js, v: GoodJob::VERSION), nonce: true %>
14
17
 
15
- <%= javascript_include_tag rails_ujs_path(format: :js, v: GoodJob::VERSION), nonce: true %>
18
+ <%= javascript_include_tag rails_ujs_url(format: :js, v: GoodJob::VERSION), nonce: true %>
16
19
  </head>
17
20
  <body>
18
21
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
19
22
  <div class="container-fluid">
20
23
  <%= link_to "GoodJob 👍", root_path, class: 'navbar-brand mb-0 h1' %>
21
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
24
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
22
25
  <span class="navbar-toggler-icon"></span>
23
26
  </button>
24
27
 
@@ -27,7 +27,7 @@ module GoodJob
27
27
  # @param queues [String, nil] determines which queues to execute jobs from when +execution_mode+ is set to +:async+. See {file:README.md#optimize-queues-threads-and-processes} for more details on the format of this string. You can also set this with the environment variable +GOOD_JOB_QUEUES+. Defaults to +"*"+.
28
28
  # @param poll_interval [Integer, nil] sets the number of seconds between polls for jobs when +execution_mode+ is set to +:async+. You can also set this with the environment variable +GOOD_JOB_POLL_INTERVAL+. Defaults to +1+.
29
29
  # @param start_async_on_initialize [Boolean] whether to start the async scheduler when the adapter is initialized.
30
- def initialize(execution_mode: nil, queues: nil, max_threads: nil, poll_interval: nil, start_async_on_initialize: Rails.application.initialized?)
30
+ def initialize(execution_mode: nil, queues: nil, max_threads: nil, poll_interval: nil, start_async_on_initialize: GoodJob.async_ready?)
31
31
  @configuration = GoodJob::Configuration.new(
32
32
  {
33
33
  execution_mode: execution_mode,
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoodJob # :nodoc:
4
+ # Extends GoodJob module to track Rails boot dependencies.
5
+ module Dependencies
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ # @!attribute [rw] _rails_after_initialize_hook_called
10
+ # @!scope class
11
+ # Whether Railtie.after_initialize has been called yet (default: +false+).
12
+ # This will be set on but before +Rails.application.initialize?+ is +true+.
13
+ # @return [Boolean]
14
+ mattr_accessor :_rails_after_initialize_hook_called, default: false
15
+
16
+ # @!attribute [rw] _active_job_loaded
17
+ # @!scope class
18
+ # Whether ActiveJob has loaded (default: +false+).
19
+ # @return [Boolean]
20
+ mattr_accessor :_active_job_loaded, default: false
21
+
22
+ # @!attribute [rw] _active_record_loaded
23
+ # @!scope class
24
+ # Whether ActiveRecord has loaded (default: +false+).
25
+ # @return [Boolean]
26
+ mattr_accessor :_active_record_loaded, default: false
27
+ end
28
+
29
+ class_methods do
30
+ # Whether GoodJob's has been initialized as of the calling of +Railtie.after_initialize+.
31
+ # @return [Boolean]
32
+ def async_ready?
33
+ Rails.application.initialized? || (
34
+ _rails_after_initialize_hook_called &&
35
+ _active_job_loaded &&
36
+ _active_record_loaded
37
+ )
38
+ end
39
+
40
+ def start_async_adapters
41
+ return unless async_ready?
42
+
43
+ GoodJob::Adapter.instances
44
+ .select(&:execute_async?)
45
+ .reject(&:async_started?)
46
+ .each(&:start_async)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -34,9 +34,18 @@ module GoodJob
34
34
  next if query.blank?
35
35
 
36
36
  tsvector = "(to_tsvector('english', serialized_params) || to_tsvector('english', id::text) || to_tsvector('english', COALESCE(error, '')::text))"
37
- where("#{tsvector} @@ to_tsquery(?)", query)
38
- .order(sanitize_sql_for_order([Arel.sql("ts_rank(#{tsvector}, to_tsquery(?))"), query]) => 'DESC')
37
+ to_tsquery_function = database_supports_websearch_to_tsquery? ? 'websearch_to_tsquery' : 'plainto_tsquery'
38
+ where("#{tsvector} @@ #{to_tsquery_function}(?)", query)
39
+ .order(sanitize_sql_for_order([Arel.sql("ts_rank(#{tsvector}, #{to_tsquery_function}(?))"), query]) => 'DESC')
39
40
  end)
40
41
  end
42
+
43
+ class_methods do
44
+ def database_supports_websearch_to_tsquery?
45
+ return @_database_supports_websearch_to_tsquery if defined?(@_database_supports_websearch_to_tsquery)
46
+
47
+ @_database_supports_websearch_to_tsquery = connection.postgresql_version >= 110000
48
+ end
49
+ end
41
50
  end
42
51
  end
@@ -206,7 +206,7 @@ module GoodJob
206
206
  good_job_tag = ["ActiveJob"].freeze
207
207
 
208
208
  self.class.loggers.inject(block) do |inner, each_logger|
209
- if each_logger.respond_to?(:tagged)
209
+ if each_logger.respond_to?(:tagged) && each_logger.formatter
210
210
  tags_for_logger = if each_logger.formatter.current_tags.include?("ActiveJob")
211
211
  good_job_tag + tags
212
212
  else
@@ -34,8 +34,27 @@ module GoodJob
34
34
  end
35
35
 
36
36
  initializer "good_job.start_async" do
37
+ # This hooks into the hookable places during Rails boot, which is unfortunately not Rails.application.initialized?
38
+ # If an Adapter is initialized during boot, we want to want to start its async executors once the framework dependencies have loaded.
39
+ # When exactly that happens is out of our control because gems or application code may touch things earlier than expected.
40
+ # For example, as of Rails 6.1, if an ActiveRecord model is touched during boot, that triggers ActiveRecord to load,
41
+ # which touches DestroyAssociationAsyncJob, which loads ActiveJob, which may initialize a GoodJob::Adapter, all of which
42
+ # happens _before_ ActiveRecord finishes loading. GoodJob will deadlock if an async executor is started in the middle of
43
+ # ActiveRecord loading.
44
+
37
45
  config.after_initialize do
38
- GoodJob::Adapter.instances.each(&:start_async)
46
+ ActiveSupport.on_load(:active_record) do
47
+ GoodJob._active_record_loaded = true
48
+ GoodJob.start_async_adapters
49
+ end
50
+
51
+ ActiveSupport.on_load(:active_job) do
52
+ GoodJob._active_job_loaded = true
53
+ GoodJob.start_async_adapters
54
+ end
55
+
56
+ GoodJob._rails_after_initialize_hook_called = true
57
+ GoodJob.start_async_adapters
39
58
  end
40
59
  end
41
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '2.9.0'
4
+ VERSION = '2.9.4'
5
5
  end
data/lib/good_job.rb CHANGED
@@ -18,6 +18,8 @@ require "good_job/railtie"
18
18
  #
19
19
  # +GoodJob+ is the top-level namespace and exposes configuration attributes.
20
20
  module GoodJob
21
+ include GoodJob::Dependencies
22
+
21
23
  DEFAULT_LOGGER = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout))
22
24
 
23
25
  # @!attribute [rw] active_record_parent_class
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -421,6 +421,7 @@ files:
421
421
  - lib/good_job/cron_manager.rb
422
422
  - lib/good_job/current_thread.rb
423
423
  - lib/good_job/daemon.rb
424
+ - lib/good_job/dependencies.rb
424
425
  - lib/good_job/execution.rb
425
426
  - lib/good_job/execution_result.rb
426
427
  - lib/good_job/filterable.rb