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.
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 classDelayed::Backend::ActiveRecord::Base
that can be monkey patched with minimal impact.