feat(bridge): allow random provider selection
This commit is contained in:
parent
e17b564370
commit
24e464653b
3 changed files with 58 additions and 7 deletions
|
@ -10,7 +10,7 @@ from wtforms.validators import DataRequired, NumberRange
|
|||
|
||||
from app.extensions import db
|
||||
from app.models.base import Pool
|
||||
from app.models.bridges import BridgeConf
|
||||
from app.models.bridges import BridgeConf, ProviderAllocation
|
||||
from app.portal.util import response_404, view_lifecycle
|
||||
|
||||
bp = Blueprint("bridgeconf", __name__)
|
||||
|
@ -36,6 +36,12 @@ class NewBridgeConfForm(FlaskForm): # type: ignore
|
|||
expiry_hours = IntegerField('Expiry Timer (hours)',
|
||||
description=("The number of hours to wait after a bridge is deprecated before its "
|
||||
"destruction."))
|
||||
provider_allocation = SelectField('Provider Allocation Method',
|
||||
description="How to allocate new bridges to providers.",
|
||||
choices=[
|
||||
("COST", "Use cheapest provider first"),
|
||||
("RANDOM", "Use providers randomly"),
|
||||
])
|
||||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
|
@ -51,6 +57,12 @@ class EditBridgeConfForm(FlaskForm): # type: ignore
|
|||
expiry_hours = IntegerField('Expiry Timer (hours)',
|
||||
description=("The number of hours to wait after a bridge is deprecated before its "
|
||||
"destruction."))
|
||||
provider_allocation = SelectField('Provider Allocation Method',
|
||||
description="How to allocate new bridges to providers.",
|
||||
choices=[
|
||||
("COST", "Use cheapest provider first"),
|
||||
("RANDOM", "Use providers randomly"),
|
||||
])
|
||||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
|
@ -85,6 +97,7 @@ def bridgeconf_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
|||
bridgeconf.target_number = form.target_number.data
|
||||
bridgeconf.max_number = form.max_number.data
|
||||
bridgeconf.expiry_hours = form.expiry_hours.data
|
||||
bridgeconf.provider_allocation = ProviderAllocation[form.provider_allocation.data]
|
||||
bridgeconf.created = datetime.utcnow()
|
||||
bridgeconf.updated = datetime.utcnow()
|
||||
try:
|
||||
|
@ -115,12 +128,14 @@ def bridgeconf_edit(bridgeconf_id: int) -> ResponseReturnValue:
|
|||
target_number=bridgeconf.target_number,
|
||||
max_number=bridgeconf.max_number,
|
||||
expiry_hours=bridgeconf.expiry_hours,
|
||||
provider_allocation=bridgeconf.provider_allocation.name,
|
||||
)
|
||||
if form.validate_on_submit():
|
||||
bridgeconf.description = form.description.data
|
||||
bridgeconf.target_number = form.target_number.data
|
||||
bridgeconf.max_number = form.max_number.data
|
||||
bridgeconf.expiry_hours = form.expiry_hours.data
|
||||
bridgeconf.provider_allocation = ProviderAllocation[form.provider_allocation.data]
|
||||
bridgeconf.updated = datetime.utcnow()
|
||||
try:
|
||||
db.session.commit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue