-
Notifications
You must be signed in to change notification settings - Fork 4
Handle no priority set case. Take CP config refresh delay from config #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import asyncio | ||
| import logging | ||
|
|
||
| from torpedo import CONFIG | ||
|
|
||
| from app.constants import Channels | ||
| from app.services.handlers.email.handler import EmailHandler | ||
| from app.services.handlers.sms.handler import SmsHandler | ||
|
|
@@ -13,7 +15,7 @@ | |
|
|
||
| class ChannelPartners: | ||
|
|
||
| _periodic_sync_delay = 5*60 | ||
| _periodic_sync_delay = CONFIG.config["CHANNEL_PARTNERS"]["CONFIG_SYNC_DELAY"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PERFORMANCE: The |
||
| PROVIDERS_CONFIG = dict() | ||
|
|
||
| @classmethod | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,10 @@ def get_default_priority(cls) -> list: | |
| def get_priority_logic(cls) -> str: | ||
| return cls._HANDLER_CONFIG["dynamic_priority"] | ||
|
|
||
| @classmethod | ||
| def get_configured_gateways(cls) -> list: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| return list(cls.PROVIDERS.keys()) | ||
|
|
||
| @classmethod | ||
| def update_configuration(cls, handler_configuration: dict): | ||
| cls._HANDLER_CONFIG = handler_configuration | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,14 @@ def get_default_priority(cls) -> list: | |
| """ | ||
| pass | ||
|
|
||
| @classmethod | ||
| @abstractmethod | ||
| def get_configured_gateways(cls) -> list: | ||
| """ | ||
| This abstract method must be overridden by the channel handler | ||
| """ | ||
| pass | ||
|
|
||
| @classmethod | ||
| def select_gateway(cls, n_attempts: int, request_data: dict) -> str: | ||
| """ | ||
|
|
@@ -50,4 +58,8 @@ def select_gateway(cls, n_attempts: int, request_data: dict) -> str: | |
| # Log the exception and fallback to default priority order | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| return current_priority[n_attempts % total_gateways] | ||
| else: | ||
| all_gateways = cls.get_configured_gateways() | ||
| return all_gateways[n_attempts % len(all_gateways)] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RUNTIME_ERROR: The new configuration parameter
CONFIG_SYNC_DELAYis 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.