-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run update call on recurring schedule #1268
Conversation
bcf29ba
to
93dcd98
Compare
@@ -885,3 +882,9 @@ async def delete_persona(persona_name: str): | |||
except Exception: | |||
logger.exception("Error while deleting persona") | |||
raise HTTPException(status_code=500, detail="Internal server error") | |||
|
|||
|
|||
@cachetools.func.ttl_cache(maxsize=128, ttl=20 * 60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the caching here since I do not want to cache the backend calls.
are trivial, and a simple hand-rolled solution is sufficient. | ||
""" | ||
|
||
def __init__(self, client: UpdateClient, interval_seconds: int = 14400): # 4 hours in seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we want this interval to be externally configurable?
Call to the update service every four hours, and use the BE origin type. Print a warning level log message if an update is available. This PR also introduces some refactoring from the previous PR: 1) Refactor the update client to be a singleton. 2) Set the instance ID once on application load. 3) Get rid of the feature flag - using the new service is now default.
93dcd98
to
7cef43f
Compare
e783820
to
b784f20
Compare
@@ -75,18 +75,20 @@ def test_health_check(test_client: TestClient) -> None: | |||
assert response.json() == {"status": "healthy"} | |||
|
|||
|
|||
@patch("codegate.api.v1_processing.fetch_latest_version", return_value="foo") | |||
def test_version_endpoint(mock_fetch_latest_version, test_client: TestClient) -> None: | |||
@patch("codegate.api.v1._get_latest_version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this test would use a patched out UpdateClient instance, but it's difficult to patch out a singleton with the mocks.
This sort of testing would be much easier if the V1 routes were defined in a class, and all dependencies were supplied via the constructor.
Call to the update service every four hours, and use the BE origin type. Print a warning level log message if an update is available.
This PR also introduces some refactoring from the previous PR: