Skip to content

Conversation

marcus-oscarsson
Copy link
Member

@marcus-oscarsson marcus-oscarsson commented Jul 9, 2025

I've had this code for the ComponentResourceHandler more or less ready for some time and I decided that its time to at-least share it for input and ideas.

The priority is still to migrate the components that are directly related to hardware objects to adapters, at-least where its feasible. That basically concerns all components except: log, csp_report, login, ra, main. The bigger components like queue and lims may have to wait and remain components for some time.

The concept is exactly the same as for the AdapterResourceHandler, and it was possible to re-use the same configuration/definition.

The two classes ComponentResourceHandler and AdapterResourceHandler shares the same base class which means that all the validation, serialization, exception handling of input and output are the same. It also means that the routes module as can be removed. No more route decorators 🥳 !

For the sake of example I configured one component in log.py
Summary:

  • The plan is to migrate components->adapters
  • Use the ComponentResourceHandler on remaining components
  • The ComponentResourceHandler and AdapterResourceHandler uses the same mechanism for data validation and error handling
  • The routes module can finaly be removed.

@marcus-oscarsson marcus-oscarsson force-pushed the component-resource-handler branch from 4e1da33 to 7795027 Compare July 9, 2025 12:20
@marcus-oscarsson marcus-oscarsson changed the title [WIP] - Added resource handler (ComponentResourceHandler) for Components [WIP] - Added resource handler (ComponentResourceHandler) for Components Jul 9, 2025
@marcus-oscarsson marcus-oscarsson force-pushed the component-resource-handler branch 2 times, most recently from 587599a to ee0bfc5 Compare July 9, 2025 13:00
@mxcube mxcube deleted a comment from sonarqubecloud bot Jul 10, 2025
@marcus-oscarsson marcus-oscarsson marked this pull request as ready for review July 15, 2025 12:25
@marcus-oscarsson marcus-oscarsson changed the title [WIP] - Added resource handler (ComponentResourceHandler) for Components Added resource handler (ComponentResourceHandler) for Components Jul 15, 2025
@marcus-oscarsson marcus-oscarsson marked this pull request as draft July 15, 2025 15:11
@marcus-oscarsson marcus-oscarsson force-pushed the component-resource-handler branch 5 times, most recently from a83edee to 901d561 Compare July 16, 2025 15:42


class AdapterResourceHandler:
class ResourceHandler:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main logic of AdapterResourceHandler is now in base class called ResourceHandler. There are two sub classes AdapterResourceHandler and ComponentResourceHandler

"""
return f"{export['url']}"

def _create_view_func(self, export: dict[str, str]) -> Callable:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The creation of the view function is slightly different between the two resource handlers. The most important difference is that there is only one instance of a Component, while an Adapter handles several instance of HardwareObjects. The hardware object id string is hence not needed for the Component.

name, url_prefix, handler_dict, app, exports, commands, attributes
)

def _get_handler_object_route(self, export) -> str:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Adapters manage several instance of HardwareObjects, which means that need to be able to pass an id

@marcus-oscarsson marcus-oscarsson force-pushed the component-resource-handler branch 2 times, most recently from 67a4f26 to 9c763d0 Compare July 17, 2025 06:22
hwr_logger = logging.getLogger("MX3.HWR")


class Log(ComponentBase):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.py in routes no longer needed, everything is contained in the Component route definition and handler methods. The input and return data are serialized and handled the same way as for Adapters, making it much easier to handle the "data flow"

@marcus-oscarsson marcus-oscarsson marked this pull request as ready for review July 17, 2025 06:29
Copy link
Collaborator

@walesch-yan walesch-yan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great change, that works well with what is already in place.

There is only a misconfigured URL in the log.py file. (The description should also say log.py and not workflow.py for those who are wondering:))

{
"attr": "log_frontend_traceback",
"method": "POST",
"url": "/",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL should be /log_frontend_traceback

@marcus-oscarsson marcus-oscarsson force-pushed the component-resource-handler branch from 9c763d0 to 0c16b47 Compare July 17, 2025 13:33
@marcus-oscarsson marcus-oscarsson force-pushed the component-resource-handler branch from 0c16b47 to 9afba26 Compare July 17, 2025 14:53
@marcus-oscarsson marcus-oscarsson merged commit 855f826 into develop Jul 17, 2025
26 checks passed
@marcus-oscarsson marcus-oscarsson deleted the component-resource-handler branch July 17, 2025 14:58
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.

2 participants