Skip to content

Commit 2bf77e7

Browse files
committed
New quota runner configuration options
1 parent db34bd5 commit 2bf77e7

3 files changed

Lines changed: 57 additions & 5 deletions

File tree

src/models/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,22 @@ class QuotaSchedulerConfiguration(ConfigurationBase):
13231323
description="Quota scheduler period specified in seconds",
13241324
)
13251325

1326+
database_reconnection_count: PositiveInt = Field(
1327+
10,
1328+
title="Database reconnection count on startup",
1329+
description="Database reconnection count on startup. When database for "
1330+
"quota is not available on startup, the service tries to reconnect N "
1331+
"times with specified delay.",
1332+
)
1333+
1334+
database_reconnection_delay: PositiveInt = Field(
1335+
1,
1336+
title="Database reconnection delay",
1337+
description="Database reconnection delay specified in seconds. When database for "
1338+
"quota is not available on startup, the service tries to reconnect N "
1339+
"times with specified delay.",
1340+
)
1341+
13261342

13271343
class QuotaHandlersConfiguration(ConfigurationBase):
13281344
"""Quota limiter configuration.

tests/unit/models/config/test_dump_configuration.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ def test_dump_configuration(tmp_path: Path) -> None:
183183
"sqlite": None,
184184
"postgres": None,
185185
"limiters": [],
186-
"scheduler": {"period": 1},
186+
"scheduler": {
187+
"period": 1,
188+
"database_reconnection_count": 10,
189+
"database_reconnection_delay": 1,
190+
},
187191
"enable_token_history": False,
188192
},
189193
}
@@ -498,7 +502,11 @@ def test_dump_configuration_with_quota_limiters(tmp_path: Path) -> None:
498502
"type": "cluster_limiter",
499503
},
500504
],
501-
"scheduler": {"period": 10},
505+
"scheduler": {
506+
"period": 10,
507+
"database_reconnection_count": 10,
508+
"database_reconnection_delay": 1,
509+
},
502510
"enable_token_history": True,
503511
},
504512
}
@@ -678,7 +686,11 @@ def test_dump_configuration_byok(tmp_path: Path) -> None:
678686
"sqlite": None,
679687
"postgres": None,
680688
"limiters": [],
681-
"scheduler": {"period": 1},
689+
"scheduler": {
690+
"period": 1,
691+
"database_reconnection_count": 10,
692+
"database_reconnection_delay": 1,
693+
},
682694
"enable_token_history": False,
683695
},
684696
}
@@ -844,7 +856,11 @@ def test_dump_configuration_pg_namespace(tmp_path: Path) -> None:
844856
"sqlite": None,
845857
"postgres": None,
846858
"limiters": [],
847-
"scheduler": {"period": 1},
859+
"scheduler": {
860+
"period": 1,
861+
"database_reconnection_count": 10,
862+
"database_reconnection_delay": 1,
863+
},
848864
"enable_token_history": False,
849865
},
850866
}

tests/unit/models/config/test_quota_scheduler_config.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ def test_quota_scheduler_default_configuration() -> None:
1313
assert cfg is not None
1414
# default value
1515
assert cfg.period == 1
16+
assert cfg.database_reconnection_count == 10
17+
assert cfg.database_reconnection_delay == 1
1618

1719

1820
def test_quota_scheduler_custom_configuration() -> None:
1921
"""Test the custom configuration."""
20-
cfg = QuotaSchedulerConfiguration(period=10)
22+
cfg = QuotaSchedulerConfiguration(
23+
period=10,
24+
database_reconnection_count=2,
25+
database_reconnection_delay=3,
26+
)
2127
assert cfg is not None
2228
assert cfg.period == 10
29+
assert cfg.database_reconnection_count == 2
30+
assert cfg.database_reconnection_delay == 3
2331

2432

2533
def test_quota_scheduler_custom_configuration_zero_period() -> None:
@@ -32,3 +40,15 @@ def test_quota_scheduler_custom_configuration_negative_period() -> None:
3240
"""Test that negative period value raises ValidationError."""
3341
with pytest.raises(ValidationError, match="Input should be greater than 0"):
3442
QuotaSchedulerConfiguration(period=-10)
43+
44+
45+
def test_quota_scheduler_custom_configuration_negative_reconnection_count() -> None:
46+
"""Test that negative period value raises ValidationError."""
47+
with pytest.raises(ValidationError, match="Input should be greater than 0"):
48+
QuotaSchedulerConfiguration(database_reconnection_count=-10)
49+
50+
51+
def test_quota_scheduler_custom_configuration_negative_reconnection_delay() -> None:
52+
"""Test that negative period value raises ValidationError."""
53+
with pytest.raises(ValidationError, match="Input should be greater than 0"):
54+
QuotaSchedulerConfiguration(database_reconnection_delay=-10)

0 commit comments

Comments
 (0)