Conversation
- Removed status and hash_rate attributes from the Miner entity, focusing on static properties. - Introduced MinerStateSnapshot value object to encapsulate runtime operational state (status, hash rate, power consumption). - Updated schemas to reflect changes, including new MinerStateSnapshotSchema for serialization. - Modified services and policies to utilize MinerStateSnapshot for decision-making and state management. - Adjusted rule engine conditions to reference miner_state instead of miner status directly. - Ensured that miner state is not persisted in the Miner entity, aligning with the new architecture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactoring of the
Minerentity to separate static configuration from runtime operational state, applying the Single Responsibility Principle (SRP).Miner(Entity) → contains only static configuration:name,model,hash_rate_max,power_consumption_max,active,controller_idMinerStateSnapshot(Value Object) → contains runtime state:status,hash_rate,power_consumptionMinerStateSnapshotdoes not have a dedicated repository. It is built on-demand by querying miner controllers and used by the rule engine (OptimizationPolicy,RuleEngine) andDecisionalContext.This PR closes #55
Motivation
The
Minerentity had a dual responsibility:This caused:
turn_on,turn_off,update_status) that mutated state without real business logic valueChanges by Layer
Domain Layer
domain/miner/value_objects.pyMinerStateSnapshot(frozen dataclass)domain/miner/entities.pystatus,hash_rate,power_consumptionand methodsturn_on(),turn_off(),update_status()domain/policy/value_objects.pyminer_state: Optional[MinerStateSnapshot]toDecisionalContextdomain/policy/aggregate_roots.pydecide_next_action()reads fromminer_state.statusinstead ofminer.statusApplication Layer
application/interfaces.pyget_miner_status()→Optional[MinerStateSnapshot]; return type ofget_miner_details_from_controller()→Optional[MinerStateSnapshot]; removedstatusparameter fromadd_miner()application/services/miner_action_service.pyMinerStateSnapshotinstead of mutating theMinerentityapplication/services/configuration_service.pystatusfromadd_miner()application/services/optimization_service.pyMinerStateSnapshot; removedminer.turn_on()/turn_off()and post-decision state persistenceAdapter Layer
adapters/domain/miner/repositories.pySqliteMinerRepositoryandSqlAlchemyMinerRepositoryadapters/domain/miner/tables.pyMinerStatusTypeclass; removed columnsstatus,hash_rate,power_consumptionfromminers_table; simplified event listenersadapters/domain/miner/schemas.pyMinerSchemaandMinerCreateSchema; addedMinerStateSnapshotSchemaadapters/domain/miner/fast_api/router.pyMinerStateSnapshotSchemaadapters/domain/miner/cli/commands.pyadapters/domain/policy/schemas.pyminer_statefield toDecisionalContextSchemaadapters/infrastructure/rule_engine/schemas.pyminer.status→miner_state.statusData / Config
data/examples/rules/stop/advanced_stop_rules.yamlminer.status→miner_state.statusdata/examples/rules/stop/basic_stop_rules.yamlminer.status→miner_state.statusMigrations
alembic/versions/4e55fe6113c7_initial_schema_with_all_tables.pystatus,hash_rate,power_consumptionfromminerstable; removedMinerStatusType()referenceTests
tests/unit/adapters/infrastructure/rule_engine/test_rule_evaluator.pymock_context.miner.status→mock_context.miner_state.status; updated field references in test conditionsBreaking Changes
Minerentity: removed fieldsstatus,hash_rate,power_consumptionand methodsturn_on(),turn_off(),update_status()/miners/{id}/statusand/miner-controllers/{id}/miner-detailsnow returnMinerStateSnapshotSchemainstead ofMinerSchema/MinerStatusminerstable no longer contains columnsstatus,hash_rate,power_consumption(requires migration for existing databases)miner.statusmust be updated tominer_state.statusDecisionalContext: access the miner's runtime state viacontext.miner_stateinstead ofcontext.minerTest Results