[nexus] factor out instance management into free functions #5622
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the instance state management code in nexus is implemented as methods on the
Nexus
type. This is problematic, as these methods can only be called in HTTP endpoints, and not from background tasks or sagas. For example, as part of #5611, I needed to call theNexus::notify_instance_updated
method from a background task, which isn't possible with the current factoring. Therefore, this PR moves that method and its dependencies, as well as all the methods in theinstance_network
module into free functions that can be called without aNexus
reference.The
Nexus
methods are left in place in order to avoid having to update all the callers as part of this PR, but they now just call into the free functions. The free functions take a few more arguments that are provided by the&self
reference in theNexus
methods, such as the internal DNSResolver
andopctx_alloc
, so the methods pass these in from&self
, making them a bit more convenient to call when aNexus
reference is available. For both of those reasons, I thought keeping them around was the right thing to do.I had briefly considered moving this code to a new
nexus-instances
crate, but it seemed a bit iffy to me asnotify_instance_updated
also unregisters an Oximeter producer, and I didn't love the idea of moving Oximeter-related code to anexus-instances
crate --- perhaps it also ought to go in anexus-oximeter
crate, or something, but that felt like a rabbit hole that I was afraid I might just end up going down forever, so I'll save it for later.If there are any functional changes as part of this PR, I've made a very bad mistake; this should be a pure refactor...