Repository navigation
Description
As a developer I find the Handler super-object confusing and difficult to work with. Blueapi should be made up of individual components, a bit like a spring boot application so it is easier to develop.
Now we run the worker in a subprocess (#317), information goes through a long chain of redundant calls including two implementations of Handler that we can probably simplify, and get rid of the Handler objects in the first place.
Probably also makes #371 easier.
Possible Solution
Currently we have:
sequenceDiagram
box Blueapi
participant FastAPI Endpoint
participant SubprocessHandler
end
box Worker Process
participant Free Function
participant Handler
participant Worker
end
FastAPI Endpoint->>SubprocessHandler: query?
SubprocessHandler->>Free Function: query?
Free Function->>Handler: query?
Handler->>Worker: query?
Worker->>Handler: response
Handler->>Free Function: response
Free Function->>SubprocessHandler: response
SubprocessHandler->>FastAPI Endpoint: response
note over Handler:Redundant
note over SubprocessHandler:Redundant
Both handlers are just forwarding calls at this point and can probably go, leaving us with:
sequenceDiagram
box Blueapi
participant FastAPI Endpoint
end
box Worker Process
participant Free Function
participant Worker
end
FastAPI Endpoint->>Free Function: query?
Free Function->>Worker: query?
Worker->>Free Function: response
Free Function->>FastAPI Endpoint: response
The complexity will be in the setup_handler code which creates a handler and configures the objects within it. That should move and should be more separated out rather than in one place. My suggestion would be to have @lru_cacheed functions to create each component (e.g. Worker, MessageTemplate, ...).
The other area of complexity will be updating the many tests that mock out Handler, but those tests are no longer accurate anyway since they pre-date the SubprocessHandler. Realistically a lot of them will need rewrites. It may be easier to do #360 first to make the tests less intrusive in the way they poke Handler.
Acceptance Criteria
BlueskyHandler,SubprocessHandlerandHandlerdeleted- Tests updated
- Tests cover subprocess case
- Any references to
Handlerin docs removed
Activity
callumforrester commentedon Apr 25, 2024
@joeshannon would appreciate your thoughts on this
joeshannon commentedon Apr 25, 2024
Yes in general the handler is overly complex and makes it difficult to work out what's going on.
Just a few clarifications/questions:
So the handler in the fastapi process would dissapear and instead just call the free functions in the subprocess directly?
Do you think there would still be a component to manage the subprocess or would it all be handled directly in the fastapi related methods?
callumforrester commentedon May 7, 2024
Good question, can see pros and cons to each. Either way there wouldn't be a component, there would be some components. The handler being one component to rule them all is frequently confusing. Do you have any views?
stan-dot commentedon May 28, 2024
additionally it's feasible to split routers this way:
#486 (comment)
Remove handler
Remove handler
Remove handler (#538)