This repository was archived by the owner on Jun 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Run update call on recurring schedule #1268
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import threading | ||
import time | ||
|
||
import structlog | ||
|
||
import codegate | ||
from codegate.updates.client import Origin, UpdateClient | ||
|
||
logger = structlog.get_logger("codegate") | ||
|
||
|
||
class ScheduledUpdateChecker(threading.Thread): | ||
""" | ||
ScheduledUpdateChecker calls the UpdateClient on a recurring interval. | ||
This is implemented as a separate thread to avoid blocking the main thread. | ||
A dedicated scheduling library could have been used, but the requirements | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we want this interval to be externally configurable? |
||
super().__init__() | ||
self.__client = client | ||
self.__interval_seconds = interval_seconds | ||
|
||
def run(self): | ||
""" | ||
Overrides the `run` method of threading.Thread. | ||
""" | ||
while True: | ||
logger.info("Checking for CodeGate updates") | ||
latest = self.__client.get_latest_version(Origin.BackEnd) | ||
if latest != codegate.__version__: | ||
logger.warning(f"A new version of CodeGate is available: {latest}") | ||
time.sleep(self.__interval_seconds) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
def test_version_endpoint(mock_get_latest_version, test_client: TestClient) -> None: | ||
"""Test the version endpoint.""" | ||
# Mock the __get_latest_version function to return a specific version | ||
mock_get_latest_version.return_value = "v1.2.3" | ||
|
||
response = test_client.get("/api/v1/version") | ||
assert response.status_code == 200 | ||
|
||
response_data = response.json() | ||
|
||
assert response_data["current_version"] == __version__.lstrip("v") | ||
assert response_data["latest_version"] == "foo" | ||
assert isinstance(response_data["is_latest"], bool) | ||
assert response_data["current_version"] == "0.1.7" | ||
assert response_data["latest_version"] == "1.2.3" | ||
assert response_data["is_latest"] is False | ||
assert response_data["error"] is None | ||
|
||
|
||
@patch("codegate.pipeline.sensitive_data.manager.SensitiveDataManager") | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.