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

Internal endpoint refactoring, handler optimizations #771

Merged
merged 11 commits into from
Dec 22, 2023

Conversation

Arksine
Copy link
Owner

@Arksine Arksine commented Dec 18, 2023

This pull request represents significant refactoring of some of Moonraker's internals. The goal is to prepare Moonraker for future additions such as:

  • Support for managing multiple connections to Klippy from one instance of moonraker
  • Support for 3rd party extensions

An overview of the items changed:

  1. Use Python enums and flags in place of strings where appropriate. This includes HTTP request methods (ie: GET, POST), tranport types (HTTP, WEBSOCKET, etc), Klippy State, and Job State.

  2. Emit a single internal event for job state changes. The legacy events remain in place for now.

  3. Optimize endpoint registration to use shared API Definitions for all transports. Previously

  4. Use a single instance of the JsonRPC class across all transports.

I have been testing this branch for a few weeks and believe that I have squashed any outstanding issues/regressions. That said, I only test against official Moonraker components. Developers and users who use optional components such as timelapse may wish to test this branch.

As of right now I intent to merge around the end of the week, presuming no regressions are discovered.

These flags replace strings as constants used to register and
identify Request Types (ie: GET, POST) and API Transport
Types.

Signed-off-by:  Eric Callahan <[email protected]>
Emit a single event where the first argument contains
a "JobEvent" enumeration that describes the particular
event.  This reduces the number of callbacks registered
by JobState consumers and allows them react to multiple
state changes in the same callback.

The individual events remain for compatibility, however
they are deprecated.  Current modules should be updated
to use the "job_state:state_changed" event and new modules
must use this event.

Signed-off-by:  Eric Callahan <[email protected]>
Refactor endpoint registration to reduce duplicated code.
Rename some APIDefinition attributes for clarity.

Signed-off-by:  Eric Callahan <[email protected]>
This change refactors the APIDefiniton into a dataclass, allowing
defs to be shared directly among HTTP and RPC requests.  In
addition, all transports now share one instance of JSONRPC,
removing duplicate registration.  API Defintiions are registered
with the RPC Dispatcher, and it validates the Transport type.
In addition tranports may perform their own validation prior
to request execution.

Signed-off-by:  Eric Callahan <[email protected]>
The default behavior of the subscribe API shares all subscription
requests.  API Transports require their own subscription.  Add
a method to facilitate this request.

Signed-off-by:  Eric Callahan <[email protected]>
Track authentication requirements in the API Definition.  This
eliminates the need to look up the authentication component
to disable auth on an endpoint.

Signed-off-by:  Eric Callahan <[email protected]>
Only log registration when verbose (debug) logging is enabled.
In addition, log endpoint removal.

Signed-off-by:  Eric Callahan <[email protected]>
Add a POST /server/jsonrpc endpoint that processes jsonrpc
requests from the body.  This allows developers familiar with
the JSON-RPC API to use it in places where a websocket is not
desiriable.

Signed-off-by:  Eric Callahan <[email protected]>
@Arksine Arksine merged commit aa16dd6 into master Dec 22, 2023
2 checks passed
@Arksine Arksine deleted the dev-common-flags-20230628 branch December 22, 2023 19:47
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.

1 participant