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

Cleanup and more #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Cleanup and more #1

wants to merge 5 commits into from

Conversation

patriciomacadden
Copy link
Member

  • I ran bundle gem to generate all of the blueprint code that bundle gem generates.
  • moved stuff around
  • ran standard
  • made it work
  • still have some stuff to work on

@@ -26,4 +28,8 @@ def fetch_db_connections

connections
end

# TODO: originally this should go in ApplicationRecord. By extracting this functionality (see tenant.rb:19) into this class to share across models of this gem, this doesn't work.
# why we need it?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question for you @nazamoresco

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates the connections pool for all the available tenants.
We have to fetch the connections from the database and do this at some point.
By doing it in the ApplicationRecord class evaluation I was sure that when a record that needed access to the database was accessed we will had created this connection pools.

Why this is failing?
I can't say for sure but I have a couple of ideas we can follow, the main one being this:

  • We have commented out the # fetch_db_connections instruction, this will for sure make this fail. But maybe you try with this in and it still failed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. gonna try a different naming probably!


# TODO: originally this should go in ApplicationRecord. By extracting this functionality (see tenant.rb:19) into this class to share across models of this gem, this doesn't work.
# why we need it?
# fetch_db_connections
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea behind creating this class is that the other classes rely too much on ApplicationRecord. It's true that all apps should have an ApplicationRecord, but the reality is that it's not mandatory. By creating this intermediate class we can add stuff that both Tenant and TenantConnection use.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense 👍

unless Rails.env.test?
pid = File.read(".pumactl_pid").to_i
Process.kill("SIGUSR2", pid)
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should think about this thing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the hot restart? 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I mean, not everyone uses puma, not everyone's aware of the pidfile, etc. normally there'a a pidfile within tmp/pids. We should think about that mostly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specifically design to work with Puma, I think is a good starting point.
It could be extended after to work with other web servers but I think just puma is ok for now.

Around the pidfile it could be configurable, we could assume it is in temp/pids and allow users to set it in a initialization file otherwise!

end

# Handles mismatches between env db and tenant db and returns if this should be run again
def check_env_matching_db_configuration!(env_config, tenancy_config)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should review this thing shouldn't we?

Copy link
Collaborator

@nazamoresco nazamoresco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know and we have a call for the pending discussions

@@ -26,4 +28,8 @@ def fetch_db_connections

connections
end

# TODO: originally this should go in ApplicationRecord. By extracting this functionality (see tenant.rb:19) into this class to share across models of this gem, this doesn't work.
# why we need it?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates the connections pool for all the available tenants.
We have to fetch the connections from the database and do this at some point.
By doing it in the ApplicationRecord class evaluation I was sure that when a record that needed access to the database was accessed we will had created this connection pools.

Why this is failing?
I can't say for sure but I have a couple of ideas we can follow, the main one being this:

  • We have commented out the # fetch_db_connections instruction, this will for sure make this fail. But maybe you try with this in and it still failed.


# TODO: originally this should go in ApplicationRecord. By extracting this functionality (see tenant.rb:19) into this class to share across models of this gem, this doesn't work.
# why we need it?
# fetch_db_connections
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense 👍

lib/generators/landlord/install_generator.rb Show resolved Hide resolved
lib/generators/landlord/install_generator.rb Show resolved Hide resolved
landlord.gemspec Show resolved Hide resolved
unless Rails.env.test?
pid = File.read(".pumactl_pid").to_i
Process.kill("SIGUSR2", pid)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the hot restart? 👍

lib/landlord.rb Show resolved Hide resolved
lib/landlord/engine.rb Show resolved Hide resolved
lib/generators/landlord/install_generator.rb Show resolved Hide resolved

fetch_db_connections
STR
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicer installation :)

end
end
end
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved into a concern. it's automatically included in ApplicationRecord and also Tenant.

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