Skip to content

Get rid of Handler #434

Closed
Closed

Description

@callumforrester

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
Loading

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
Loading

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, SubprocessHandler and Handler deleted
  • Tests updated
  • Tests cover subprocess case
  • Any references to Handler in docs removed

Activity

  1. added
    enhancement
    on Apr 25, 2024
  2. callumforrester commented on Apr 25, 2024

    @callumforrester
    ContributorAuthor

    @joeshannon would appreciate your thoughts on this

  3. joeshannon commented on Apr 25, 2024

    @joeshannon
    Contributor

    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?

  4. callumforrester commented on May 7, 2024

    @callumforrester
    ContributorAuthor

    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?

  5. self-assigned this
    on May 28, 2024
  6. stan-dot commented on May 28, 2024

    @stan-dot
    Contributor

    additionally it's feasible to split routers this way:

    #486 (comment)

  7. removed their assignment
    on May 29, 2024
  8. added 3 commits that reference this issue on Jul 23, 2024
    c5887b7
    2dedbfd
    4621ed3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions