collectiveidea / delayed_job_active_record

ActiveRecord backend integration for DelayedJob 3.0+
MIT License
346 stars 336 forks source link

Don't use ActiveRecord::Base as parent class #227

Open mateuscruz opened 7 months ago

mateuscruz commented 7 months ago

We've been facing performance issues with our delayed jobs table. One of the initiatives we're experimenting on is using a separate database for delayed jobs. Rails supports multiple database connections since version 6.0 using ActiveRecord::ConnectionHandling#connects_to.

However, since 6.1, Rails does not allow using connects_to in non abstract classes to avoid opening multiple connections to the database. The recommended way to do it is to create a new abstract class and have your models that need a different connection inherit from that new abstract class.

Also, the current version of the delayed job active record backend does not support connection config. The quickest work around is to make Delayed::Backend::ActiveRecord::Job inherit from a new abstract class Delayed::Backend::ActiveRecord::Base that can be monkey patched with minimal impact.

mateuscruz commented 2 months ago

@albus522 any chance this could get reviewed?

albus522 commented 2 months ago

It's probably the right path forward but it is a breaking change so it warrants a bit more consideration