Dynamic imports and processing config #335
Replies: 3 comments 13 replies
-
Im OK with this, there are possibly some complications with this approach especially with the less straight forward components (Im sure there will also be solutions). Imports can be conditional, and I am keen to minimise absolutely required dependancies whereever possible I see the powermon code as the chance to improve/refactor as it is not 'released' yet - as an example the yaml config isnt a given, it just seemed like a better approach (expecially compared to the ever increasing command line options) |
Beta Was this translation helpful? Give feedback.
-
I've started on the changes, will be a few days before I open a pull request. I am keeping all the config parsing in the constructors and adding abstract parent types for shared configuration. The parent classes is also a good spot to put common functionality, like filters. Haven't got that far yet. I am also changing the object structure a little bit. For example instead of port and protocol being independent objects I am putting them both into a device object. Overall the changes will be fairly large. Maybe you can try checking out my branch once I'm done and giving it a test run. Which powermon file are you currently testing with? I can test it before I make the pull request. |
Beta Was this translation helpful? Give feedback.
-
Hi
also Ive tried to pull your branch so things dont diverge too much, but im not sure if that has worked - can you try to get your branch updated to master (and if you have suggestions on a better workflow please let me know as it seems hard to incorporate changes) rough eg of my thinking scheduling:
loop_duration: 60
schedules:
- name: default # doesnt need to be defined as exists automatically
type: once
- name: every_5_minutes
type: loop
run_every_x_loops: 5 #will run every 5 minutes
commands:
- command: QPIGS
type: basic #default command type is basic
schedule: every_5_minutes #if not defined will default to 'default'
outputs:
- name: screen
tag: Test_Inverter
|
Beta Was this translation helpful? Give feedback.
-
Before I continue coding away I wanted to go over the goal behind my refactoring and address some of the concerns you raised with the changes.
A major limitation with the use of dynamic imports is that you don't get to create a custom constructor for each object. This means the objects themselves don't contain the state required to perform their expected operations. So when you call a method on these low state objects a lot of state needs to be included. So this results in a lot state being passed around and the need for the kwargs pattern. The more external state the object depends on the more difficult it is to read it's methods without the context of the code that calls it.
To help reduce the complexity of the code I would like to process all the configuration up front and load it into member variables in the objects. Then the method calls don't require a lot of parameters passed in and will be easier to understand. To accomplish this I will use an object factory pattern that takes in the configuration and returns a complete object. After the model is constructed the configuration will no longer be referenced. This will help with the creation of an API that can change how powermon operates while running.
I do hear your concern about problematic lib imports and I think the importlib idea will still be useful while being used selectively. For example, say a MongoDBOutput type includes a bunch of imports that impacts performance. Within the MongoDBOutput class we can use the importlib to load the Mongo drivers. That way we can still reference the MongoDBOutput class but we only need to install the driver libs if we plan on calling it.
Beta Was this translation helpful? Give feedback.
All reactions