Skip to content

Commit 32740b3

Browse files
committed
Merge branch 'ml-evs/backoff_time' into v1.2_staging_arena
2 parents b08053d + 8ca2fd0 commit 32740b3

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

openapi/index_openapi.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,12 @@
17351735
"type": "string",
17361736
"description": "response string from the server"
17371737
},
1738+
"request_delay": {
1739+
"title": "Request Delay",
1740+
"minimum": 0.0,
1741+
"type": "number",
1742+
"description": "A non-negative float giving time in seconds that the client is suggested to wait before issuing a subsequent request."
1743+
},
17381744
"implementation": {
17391745
"title": "Implementation",
17401746
"allOf": [

openapi/openapi.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4145,6 +4145,12 @@
41454145
"type": "string",
41464146
"description": "response string from the server"
41474147
},
4148+
"request_delay": {
4149+
"title": "Request Delay",
4150+
"minimum": 0.0,
4151+
"type": "number",
4152+
"description": "A non-negative float giving time in seconds that the client is suggested to wait before issuing a subsequent request."
4153+
},
41484154
"implementation": {
41494155
"title": "Implementation",
41504156
"allOf": [

optimade/models/optimade_json.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
from enum import Enum
55
from typing import Any, Dict, List, Optional, Type, Union
66

7-
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, EmailStr, root_validator
7+
from pydantic import (
8+
AnyHttpUrl,
9+
AnyUrl,
10+
BaseModel,
11+
EmailStr,
12+
NonNegativeFloat,
13+
root_validator,
14+
)
815

916
from optimade.models import jsonapi
1017
from optimade.models.utils import SemanticVersion, StrictField
@@ -324,6 +331,11 @@ class ResponseMeta(jsonapi.Meta):
324331
None, description="response string from the server"
325332
)
326333

334+
request_delay: Optional[NonNegativeFloat] = StrictField(
335+
None,
336+
description="A non-negative float giving time in seconds that the client is suggested to wait before issuing a subsequent request.",
337+
)
338+
327339
implementation: Optional[Implementation] = StrictField(
328340
None, description="a dictionary describing the server implementation"
329341
)

optimade/server/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,27 @@ class ServerConfig(BaseSettings):
299299
description="If True, the server will check whether the query parameters given in the request are correct.",
300300
)
301301

302+
request_delay: Optional[float] = Field(
303+
None,
304+
description=(
305+
"The value to use for the `meta->request_delay` field, which indicates to clients how long they should leave between success queries."
306+
),
307+
)
308+
302309
@validator("implementation", pre=True)
303310
def set_implementation_version(cls, v):
304311
"""Set defaults and modify bypassed value(s)"""
305312
res = {"version": __version__}
306313
res.update(v)
307314
return res
308315

316+
@validator("request_delay", pre=True)
317+
def check_request_delay(cls, v):
318+
"""Check `request_delay` is non-negative."""
319+
if v is not None and v < 0:
320+
raise ValueError("`request_delay` must be non-negative")
321+
return v
322+
309323
@root_validator(pre=True)
310324
def use_real_mongo_override(cls, values):
311325
"""Overrides the `database_backend` setting with MongoDB and

optimade/server/routers/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def meta_values(
7676
if schema is None:
7777
schema = CONFIG.schema_url if not CONFIG.is_index else CONFIG.index_schema_url
7878

79+
if CONFIG.request_delay is not None:
80+
# Add request delay via **kwargs only so that it is not set to null by default
81+
kwargs["request_delay"] = CONFIG.request_delay
82+
7983
return ResponseMeta(
8084
query=ResponseMetaQuery(representation=f"{url_path}?{url.query}"),
8185
api_version=__api_version__,

0 commit comments

Comments
 (0)