Change exponential backoff timeouts + add constants#51
Merged
Conversation
…onstant - Changed hardcoded timeout in comed.py: asyncio.timeout(60) → asyncio.timeout(Network.Defaults.HTTP_TIMEOUT) - Changed hardcoded timeout in api_client.py: aiohttp.ClientTimeout(total=60) → aiohttp.ClientTimeout(total=Network.Defaults.HTTP_TIMEOUT) - Changed hardcoded timeout in session_manager.py: timeout=60 → timeout=Network.Defaults.HTTP_TIMEOUT - Added Network import to all three files - Formatted all changes with black All 346 tests passing. Rationale: - HTTP_TIMEOUT (60s) is a safety net above FallbackManager's max timeout (45s) - Ensures consistent timeout configuration across the codebase - FallbackManager controls actual retry strategy with exponential backoff (5s → 15s → 45s) - HTTP layer timeout prevents indefinite hangs while allowing proper retry logic
enoch85
commented
Nov 2, 2025
…tants (#52) * Initial plan * Replace hardcoded max_retries=3 with Network.Defaults.RETRY_COUNT constant Co-authored-by: enoch85 <4511254+enoch85@users.noreply.github.com> * Replace hardcoded retry and delay values with Network.Defaults constants in error_handler.py Co-authored-by: enoch85 <4511254+enoch85@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: enoch85 <4511254+enoch85@users.noreply.github.com>
Owner
Author
|
@copilot Please look through the changed constants here in this PR. Then look for more occurances were we forgot to change to the use of constants instead of hard coded values. Be thorough, think deep, inspect every line of the code base. Read all the code base in sections by 400 lines each. Analyze if we need constant replacements in more places. Use your built in tools to grep, sed, and whatever you need to truly find everything. Create a PR with your changes, if any. |
…#53) * Initial plan * Replace hardcoded values with constants across codebase - Added new constants to Network.Defaults: * SECONDS_PER_HOUR = 3600 * RETRY_CUTOFF_TIME_HOUR = 23 * RETRY_CUTOFF_TIME_MINUTE = 50 * CACHE_DEFAULT_TTL_SECONDS = 3600 - Replaced hardcoded retry interval (1800) with Network.Defaults.STANDARD_UPDATE_INTERVAL_MINUTES * SECONDS_PER_MINUTE in: * api/utils.py * api/nordpool.py * api/energi_data.py * api/entsoe.py - Replaced hardcoded time(23, 50) with new RETRY_CUTOFF_TIME constants in: * api/nordpool.py * api/energi_data.py * api/entsoe.py - Replaced hardcoded cache age (6 * 60 * 60) with Network.Defaults.CACHE_TTL in: * api/base/data_fetch.py - Replaced hardcoded 15 minutes with TimeInterval.get_interval_minutes() in: * api/parsers/comed_parser.py (timedelta and // 15 calculations) * api/parsers/entsoe_parser.py (timedelta calculation) * coordinator/data_validity.py (timedelta calculation) - Replaced hardcoded fetch_interval_minutes default (15) with Network.Defaults.MIN_UPDATE_INTERVAL_MINUTES in: * coordinator/fetch_decision.py - Replaced hardcoded 3600 with CACHE_DEFAULT_TTL_SECONDS or SECONDS_PER_HOUR in: * utils/advanced_cache.py (default TTL) * timezone/dst_handler.py (time conversions) * timezone/interval_calculator.py (time conversions) - Replaced hardcoded * 60 conversions with Network.Defaults.SECONDS_PER_MINUTE in: * coordinator/cache_manager.py * coordinator/unified_price_manager.py All files formatted with black. Syntax validated successfully. Co-authored-by: enoch85 <4511254+enoch85@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: enoch85 <4511254+enoch85@users.noreply.github.com>
This comment was marked as outdated.
This comment was marked as outdated.
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.
Eliminates hardcoded timeout, retry, cache TTL, and time conversion values across 17 files, replacing them with centralized constants from
Network.DefaultsandTimeInterval.Changes
Added constants to
Network.Defaults:SECONDS_PER_HOUR = 3600RETRY_CUTOFF_TIME_HOUR = 23,RETRY_CUTOFF_TIME_MINUTE = 50CACHE_DEFAULT_TTL_SECONDS = 3600Replaced hardcoded values:
60→Network.Defaults.HTTP_TIMEOUTincomed.py,api_client.py,session_manager.pymax_retries=3→Network.Defaults.RETRY_COUNTinerror_handler.py1800→Network.Defaults.STANDARD_UPDATE_INTERVAL_MINUTES * SECONDS_PER_MINUTEin 4 API clientstime(23, 50)→time(RETRY_CUTOFF_TIME_HOUR, RETRY_CUTOFF_TIME_MINUTE)in 3 API clients6 * 60 * 60→Network.Defaults.CACHE_TTLindata_fetch.py15→TimeInterval.get_interval_minutes()in 3 parsers/coordinators3600,* 60→SECONDS_PER_HOUR,SECONDS_PER_MINUTEin 5 utility modulesExample: