Handle no priority set case. Take CP config refresh delay from config#14
Handle no priority set case. Take CP config refresh delay from config#14
Conversation
|
DeputyDev has started reviewing your pull request. |
| class ChannelPartners: | ||
|
|
||
| _periodic_sync_delay = 5*60 | ||
| _periodic_sync_delay = CONFIG.config["CHANNEL_PARTNERS"]["CONFIG_SYNC_DELAY"] |
There was a problem hiding this comment.
PERFORMANCE: The _periodic_sync_delay value is now being read from the configuration file, which is a good practice. However, there's no validation or error handling for this value. If the configuration is missing or invalid, it could lead to unexpected behavior. Consider adding a default value and error handling to ensure the system behaves predictably even if the configuration is missing or invalid.
class ChannelPartners:
_periodic_sync_delay = CONFIG.config.get("CHANNEL_PARTNERS", {}).get("CONFIG_SYNC_DELAY", 300) # Default to 5 minutes
PROVIDERS_CONFIG = dict()
@classmethod
def __init__(cls):
if cls._periodic_sync_delay <= 0:
logger.warning("Invalid CONFIG_SYNC_DELAY, using default of 300 seconds")
cls._periodic_sync_delay = 300
| @@ -13,7 +15,7 @@ | |||
|
|
|||
| class ChannelPartners: | |||
|
|
|||
There was a problem hiding this comment.
RUNTIME_ERROR: The new configuration parameter CONFIG_SYNC_DELAY is introduced, but there's no error handling if this configuration is missing. This could lead to a runtime error if the configuration is not properly set.
# Add a default value and error handling
_periodic_sync_delay = CONFIG.config.get("CHANNEL_PARTNERS", {}).get("CONFIG_SYNC_DELAY", 300) # Default to 5 minutes
| return cls._HANDLER_CONFIG["dynamic_priority"] | ||
|
|
||
| @classmethod | ||
| def get_configured_gateways(cls) -> list: |
There was a problem hiding this comment.
CODE_ROBUSTNESS: The addition of the get_configured_gateways method to the AbstractHandler class enhances code robustness by providing a fallback mechanism when no gateways are available in the priority list.
| pass | ||
| total_gateways = min(len(cls.get_default_priority()), len(current_priority)) | ||
| return current_priority[n_attempts % total_gateways] | ||
| if total_gateways > 0: |
There was a problem hiding this comment.
CODE_ROBUSTNESS: The code now handles the case when no priority is set or when the total_gateways is 0, improving the robustness of the gateway selection process.
|
DeputyDev has completed a review of your pull request for commit 105345c. |
Size S: This PR changes include 25 lines and should take approximately 15-30 minutes to review
DeputyDev generated PR summary:
The pull request (PR) introduces several changes aimed at improving the configuration handling and gateway selection logic for channel partners in the system. Here's a breakdown of what the PR does:
Configuration Synchronization Delay:
_periodic_sync_delayin theChannelPartnersclass is now dynamically set using a value from a configuration file (CONFIG.config["CHANNEL_PARTNERS"]["CONFIG_SYNC_DELAY"]) instead of a hardcoded value. This allows for easier adjustments of the sync delay without modifying the code.New Method for Configured Gateways:
get_configured_gatewaysis added to theabstract_handler.pyandgateway_priority.pyfiles. This method returns a list of configured gateways and is intended to be overridden by subclasses. This change enhances the flexibility and extensibility of the handler classes.Gateway Selection Logic:
select_gatewaymethod ingateway_priority.pyhas been updated to handle cases where no default priority order is available. Iftotal_gatewaysis zero, it now falls back to using all configured gateways to select from, ensuring that the system can still function even if priority configurations are missing.Configuration Template Update:
config_template.jsonfile is updated to include a new configuration section forCHANNEL_PARTNERS, which includesCONFIG_SYNC_DELAY.These changes improve the configurability and robustness of the system by allowing dynamic configuration of sync delays and enhancing gateway selection logic to handle edge cases more gracefully.
Here's the corrective code in markdown format: