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

Update Reloading to Support Zeitwerk in Rails Development Environment #1675

Open
nathancolgate opened this issue Sep 22, 2022 · 6 comments
Open

Comments

@nathancolgate
Copy link

ActiveGraph relies on a Rails 3.x method for cache clearing: before_remove_const.

We are running with the gem in a Rails 7 app. So the method is never called, and as such, we must restart our development server anytime we make a change to a node instance method.

FWIW: There is a Rails guide for upgrading it to Zeitwerk (the latest reloading library).

In our application, we monkey patch this in the initializer. It's one-to-one re-write of the current before_remove_const method. It's not perfect: we must add each ActiveGraph node (relationships are OK as-is), but it works:

Code example (initializers/neo4j.rb)

unless Rails.application.config.cache_classes
  node_classes = [
    "StateSecret",
    "LaunchCode",
    "Bribe",
    "User"
  ]
  node_classes.each do |node_class|
    Rails.autoloaders.main.on_unload(node_class) do |klass, _abspath|
      klass.associations.each_value(&:queue_model_refresh!)
      klass::MODELS_FOR_LABELS_CACHE.clear
      klass::WRAPPED_CLASSES.each { |c| klass::MODELS_TO_RELOAD << c.name }
      klass::WRAPPED_CLASSES.clear
    end
  end
end

Runtime information:

Neo4j database version: neo4j:4.0.9-community
activegraph gem version: 10.2.0.beta.1
rails gem version: 7.0.3

@klobuczek
Copy link
Member

Thank you for the report. We converted all our gems to zeitwerk except this one. I would love to get it done. Will conversion to zeitwerk alone fix your problems?
We will probably do it on version 11.1.0 only. Will that work for you?

@nathancolgate
Copy link
Author

@klobuczek I'm not sure.

We are running Rails 7 which requires Ruby 2.7.0 or newer in ruby:3.1.2-slim-bulleye. The latest version of JRuby is 9.3.8.0, which is only compatible with Ruby 2.6.x. So that seems to point to "no".

But this issue has a checklist of issues to fix to get Rails 7 working on JRuby... and they're all checked off. So that seems to point to "yes".

We're not too worried about it at this point. Most of my motivation in opening this issue was to help anyone else that might be trying to accomplish the same thing we are.

@klobuczek
Copy link
Member

@nathancolgate I'm talking about
activegraph 11.1.0.alpha.4
with
neo4j-ruby-driver 4.4.0.beta.1
which requires ruby 3.1.2 if on MRI

@nathancolgate
Copy link
Author

@klobuczek oh! I'm not sure. The README mentions v11 only being available on jRuby.

@klobuczek
Copy link
Member

we have not updated that as we have not released the MRI driver officially yet.

@nathancolgate
Copy link
Author

@klobuczek Then that should work for us! Great!

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

No branches or pull requests

2 participants