good_job 2.9.0 → 2.9.1

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: f99dea9840ebbfd8eda79dd1c06a94b7c9d8185835d6f9991e94d5a86fc5ffea
4
+ data.tar.gz: 148b147b8f76c74f0362dcc8b26381631e1582eae4e7ab929021a291fa7d24fa
5
5
  SHA512:
6
- metadata.gz: d2ade6a5c9b26e1d9d1bc1522dc10159f78943b5da249effa1405dccf5c3de5078f74a08c27657eef63d51967bb04eb8486d933e9d817664a25c33f3740f2280
7
- data.tar.gz: 40dc9f0b3b1d210ddcec9d7ce5dd7014e2409d5602bb4b3c55314b5bf799ef29fab9fd0764931c2026242c91383a335b64c4f3243ea16d50997e59ef9c7820e3
6
+ metadata.gz: fe4926720862cb1e42581aa612b92c46ed9a00ea183b66a6c9ee4836165a7f77aa10b78ed32c80399bdc39189f76cd5f48e7b98e3b9b7da93b0de71c8b3cd0c7
7
+ data.tar.gz: 1e47650d6bbdca91983bce0df607e4e4845cd26339d87798086a85f89be822987c2c41cfab08aba164f89195c55d10b3129e593b873b95dfb4075d452e3541c2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.9.1](https://github.com/bensheldon/good_job/tree/v2.9.1) (2022-01-13)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.9.0...v2.9.1)
6
+
7
+ **Closed issues:**
8
+
9
+ - Graceful fallback to polling when LISTEN/NOTIFY isn't available [\#482](https://github.com/bensheldon/good_job/issues/482)
10
+ - Long running locks on latest good job [\#480](https://github.com/bensheldon/good_job/issues/480)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - 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))
15
+
3
16
  ## [v2.9.0](https://github.com/bensheldon/good_job/tree/v2.9.0) (2022-01-09)
4
17
 
5
18
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.8.1...v2.9.0)
data/README.md CHANGED
@@ -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
@@ -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,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.1'
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.1
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-13 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