-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Rails 7.1 regression: Delayed::JobWrapper not defined (#30)
This fixes #29, which can be reproduced on new Rails 7.1.1 apps in development. The issue stems from the fact that Rails no longer loads ActiveJob at all until the first `ActiveJob::Base` class is referenced, but we defined our `Delayed::JobWrapper` class in a file that only loads _after_ ActiveJob loads. This means that you can enqueue an ActiveJob, but the first time `delayed:work` tries to deserialize the handler, it encounters the `Delayed::JobWrapper` constant before it encounters its first `ActiveJob::Base` class. The fix is to pull `Delayed::JobWrapper` out into its own file in `lib/` and load it when `lib/delayed.rb` loads. The class itself has no dependencies outside of `activesupport` (`delegate_missing_to`) so this is safe enough to do.
- Loading branch information
Showing
4 changed files
with
33 additions
and
31 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
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,31 @@ | ||
module Delayed | ||
class JobWrapper # rubocop:disable Betterment/ActiveJobPerformable | ||
attr_accessor :job_data | ||
|
||
delegate_missing_to :job | ||
|
||
def initialize(job_data) | ||
@job_data = job_data | ||
end | ||
|
||
def display_name | ||
job_data['job_class'] | ||
end | ||
|
||
def perform | ||
ActiveJob::Callbacks.run_callbacks(:execute) do | ||
job.perform_now | ||
end | ||
end | ||
|
||
def encode_with(coder) | ||
coder['job_data'] = @job_data | ||
end | ||
|
||
private | ||
|
||
def job | ||
@job ||= ActiveJob::Base.deserialize(job_data) if job_data | ||
end | ||
end | ||
end |