Skip to content

Conversation

@mateuscruz
Copy link

@mateuscruz mateuscruz commented Apr 11, 2024

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
Copy link
Author

@albus522 any chance this could get reviewed?

@albus522
Copy link
Member

albus522 commented Sep 6, 2024

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

@mateuscruz
Copy link
Author

@albus522 I hope you've had time to consider this?

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 recommeneded 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants