Betterment / delayed

a multi-threaded, SQL-driven ActiveJob backend used at Betterment to process millions of background jobs per day
MIT License
154 stars 8 forks source link

Fix Rails 7.1 regression: Delayed::JobWrapper not defined #30

Closed smudge closed 11 months ago

smudge commented 11 months ago

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.

/no-platform