code review feedback

This commit is contained in:
Kenneth Kehl
2023-08-15 14:50:41 -07:00
parent c5008da8df
commit f2f0e5a0f1
10 changed files with 2 additions and 165 deletions

View File

@@ -28,9 +28,6 @@ from app.dao.jobs_dao import (
find_missing_row_for_job,
)
from app.dao.notifications_dao import notifications_not_yet_sent
from app.dao.provider_details_dao import (
dao_adjust_provider_priority_back_to_resting_points,
)
from app.dao.services_dao import (
dao_find_services_sending_to_tv_numbers,
dao_find_services_with_high_failure_rates,
@@ -85,11 +82,6 @@ def delete_invitations():
raise
@notify_celery.task(name='tend-providers-back-to-middle')
def tend_providers_back_to_middle():
dao_adjust_provider_priority_back_to_resting_points()
@notify_celery.task(name='check-job-status')
def check_job_status():
"""

View File

@@ -74,59 +74,6 @@ def _get_sms_providers_for_update(time_threshold):
return q
@autocommit
def dao_reduce_sms_provider_priority(identifier, *, time_threshold):
"""
Will reduce a chosen sms provider's priority, and increase the other provider's priority by 10 points each.
If either provider has been updated in the last `time_threshold`, then it won't take any action.
"""
# amount_to_reduce_by = 10
providers_list = _get_sms_providers_for_update(time_threshold)
if len(providers_list) < 2:
current_app.logger.info("Not adjusting providers, number of active providers is less than 2.")
return
# TODO right now we only have one provider. Remove this?
# providers = {provider.identifier: provider for provider in providers_list}
# other_identifier = get_alternative_sms_provider(identifier)
#
# reduced_provider = providers[identifier]
# increased_provider = providers[other_identifier]
#
# # always keep values between 0 and 100
# reduced_provider_priority = max(0, reduced_provider.priority - amount_to_reduce_by)
# increased_provider_priority = min(100, increased_provider.priority + amount_to_reduce_by)
#
# _adjust_provider_priority(reduced_provider, reduced_provider_priority)
# _adjust_provider_priority(increased_provider, increased_provider_priority)
@autocommit
def dao_adjust_provider_priority_back_to_resting_points():
"""
Provided that neither SMS provider has been modified in the last hour, move both providers by 10 percentage points
each towards their defined resting points (set in SMS_PROVIDER_RESTING_POINTS in config.py).
"""
# TODO we only have one provider. Remove?
# amount_to_reduce_by = 10
# time_threshold = timedelta(hours=1)
#
# providers = _get_sms_providers_for_update(time_threshold)
#
# for provider in providers:
# target = current_app.config['SMS_PROVIDER_RESTING_POINTS'][provider.identifier]
# current = provider.priority
#
# if current != target:
# if current > target:
# new_priority = max(target, provider.priority - amount_to_reduce_by)
# else:
# new_priority = min(target, provider.priority + amount_to_reduce_by)
#
# _adjust_provider_priority(provider, new_priority)
def get_provider_details_by_notification_type(notification_type, supports_international=False):
filters = [ProviderDetails.notification_type == notification_type]

View File

@@ -1,5 +1,5 @@
import random
from datetime import datetime, timedelta
from datetime import datetime
from urllib import parse
from cachetools import TTLCache, cached
@@ -18,7 +18,6 @@ from app.celery.research_mode_tasks import (
from app.dao.email_branding_dao import dao_get_email_branding_by_id
from app.dao.notifications_dao import dao_update_notification
from app.dao.provider_details_dao import (
dao_reduce_sms_provider_priority,
get_provider_details_by_notification_type,
)
from app.exceptions import NotificationTechnicalFailureException
@@ -82,7 +81,6 @@ def send_sms_to_provider(notification):
except Exception as e:
notification.billable_units = template.fragment_count
dao_update_notification(notification)
dao_reduce_sms_provider_priority(provider.name, time_threshold=timedelta(minutes=1))
raise e
else:
notification.billable_units = template.fragment_count

View File

@@ -679,10 +679,7 @@ class ServiceInboundApi(db.Model, Versioned):
@property
def bearer_token(self):
# Column is non-nullable
# if self._bearer_token:
return encryption.decrypt(self._bearer_token)
# return None
@bearer_token.setter
def bearer_token(self, bearer_token):
@@ -719,10 +716,7 @@ class ServiceCallbackApi(db.Model, Versioned):
@property
def bearer_token(self):
# There is a non-null constraint on this column
# if self._bearer_token:
return encryption.decrypt(self._bearer_token)
# return None
@bearer_token.setter
def bearer_token(self, bearer_token):
@@ -777,10 +771,7 @@ class ApiKey(db.Model, Versioned):
@property
def secret(self):
# Column is non-nullable
# if self._secret:
return encryption.decrypt(self._secret)
# return None
@secret.setter
def secret(self, secret):