Skip to content

Uniform registration of instances and servicers

Cal Pratt requested to merge cpratt34/server-refactor into master

Description

There is currently a lot of abstraction surrounding attaching an instance to a servicer in the Server. The pattern currently used creates a circular dependency between the Server and the instances, and results in a lot of duplicated logic in the servicer/instance setups. The pattern is very strict on class setup, however, none of this logic is enforced by any interface, making it difficult to add new servicer implementations to the mix, and allows for confusing exceptions to the rules which are non-obvious to developers.

This change pulls out the registration logic from the individual instance implementations and moves them into the server. To assist the server with registering instances to servicers, a set of generic base classes have been included in buildgrid.server.servicer. Servicer instances can now be created even if they will have no registered instances (logic has been added to ensure that only servicers with instances are registered to the gprc.Server instance, with special casing for the capabilities servicer).

Now that there is a consistent interface for registering a group of instances to the servicers, we can remove the majority of the setup logic found within the Server, and also avoid the circular dependencies it caused. It also removes the need for many asserts for non-initialized attributes on the server class.

Future work will include reducing the post initialization logic in the instance setup by leveraging context managers, further simplifying the setup of instances. We may also want to re-evaluate the RMQService, as this refactoring exposes a lot of lacking functionality which would now be much easier to implement.

Merge request reports