Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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.
@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

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