add dao_reduce_sms_provider_priority function

retrive the sms providers from the DB, and decrease the chosen
provider's priority by 10, while increasing the other by 10.

add a check in to ensure we never decrease below 0 or increase above 100
- this is per provider, we don't check that the two add up to 100 or
  anything. If the values are outside of this range (eg: set via the UI)
then they'll probably* fix themselves at some point - we've added tests
to document these cases.

Use with_for_update to ensure that the method can only run once at a
time - other invocations of the function will be held on that line until
the currently running one ends and commits the transaction. This doesn't
affect anyone doing things from the UI.
This commit is contained in:
Leo Hemsted
2019-11-11 14:31:58 +00:00
parent 6f38cbbcf1
commit fa7e0a1e84
4 changed files with 61 additions and 28 deletions

View File

@@ -35,7 +35,7 @@ from app.dao.notifications_dao import (
)
from app.dao.provider_details_dao import (
get_current_provider,
dao_toggle_sms_provider
dao_reduce_sms_provider_priority
)
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
from app.models import (
@@ -129,7 +129,7 @@ def switch_current_sms_provider_on_slow_delivery():
)
)
dao_toggle_sms_provider(current_provider.identifier)
dao_reduce_sms_provider_priority(current_provider.identifier)
@notify_celery.task(name='check-job-status')