-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start async adapters once
ActiveRecord
and ActiveJob
have loaded,…
… potentially before `Rails.application.initialized?` (#483)
- Loading branch information
1 parent
68ec56c
commit b052ed1
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module GoodJob # :nodoc: | ||
# Extends GoodJob module to track Rails boot dependencies. | ||
module Dependencies | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# @!attribute [rw] _rails_after_initialize_hook_called | ||
# @!scope class | ||
# Whether Railtie.after_initialize has been called yet (default: +false+). | ||
# This will be set on but before +Rails.application.initialize?+ is +true+. | ||
# @return [Boolean] | ||
mattr_accessor :_rails_after_initialize_hook_called, default: false | ||
|
||
# @!attribute [rw] _active_job_loaded | ||
# @!scope class | ||
# Whether ActiveJob has loaded (default: +false+). | ||
# @return [Boolean] | ||
mattr_accessor :_active_job_loaded, default: false | ||
|
||
# @!attribute [rw] _active_record_loaded | ||
# @!scope class | ||
# Whether ActiveRecord has loaded (default: +false+). | ||
# @return [Boolean] | ||
mattr_accessor :_active_record_loaded, default: false | ||
end | ||
|
||
class_methods do | ||
# Whether GoodJob's has been initialized as of the calling of +Railtie.after_initialize+. | ||
# @return [Boolean] | ||
def async_ready? | ||
Rails.application.initialized? || ( | ||
_rails_after_initialize_hook_called && | ||
_active_job_loaded && | ||
_active_record_loaded | ||
) | ||
end | ||
|
||
def start_async_adapters | ||
return unless async_ready? | ||
|
||
GoodJob::Adapter.instances | ||
.select(&:execute_async?) | ||
.reject(&:async_started?) | ||
.each(&:start_async) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters