Skip to content
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

Merged
merged 2 commits into from
Mar 12, 2025
Merged

Run update call on recurring schedule #1268

merged 2 commits into from
Mar 12, 2025

Conversation

dmjb
Copy link
Member

@dmjb dmjb commented Mar 12, 2025

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.

@dmjb dmjb force-pushed the call-update-service-be branch from bcf29ba to 93dcd98 Compare March 12, 2025 12:25
@@ -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)
Copy link
Member Author

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
Copy link
Member Author

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?

@dmjb dmjb marked this pull request as draft March 12, 2025 12:28
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.
@dmjb dmjb force-pushed the call-update-service-be branch from 93dcd98 to 7cef43f Compare March 12, 2025 12:40
@dmjb dmjb marked this pull request as ready for review March 12, 2025 12:40
@dmjb dmjb force-pushed the call-update-service-be branch from e783820 to b784f20 Compare March 12, 2025 13:04
@@ -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")
Copy link
Member Author

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.

@dmjb dmjb merged commit 7886f6f into main Mar 12, 2025
10 of 11 checks passed
@dmjb dmjb deleted the call-update-service-be branch March 12, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants