mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-15 21:45:10 +00:00
fix(api): cache the health update check and fix a remote-session test fixture
This commit is contained in:
@@ -58,6 +58,8 @@ Health check. **This is the only route exempt from authentication**: you can cal
|
||||
|
||||
`draining` is `true` while the server refuses new remote sessions and jobs before a restart.
|
||||
|
||||
The server asks GitHub for the latest release at most once per [`update_check_interval`](../../reference/configuration/misc.md#caching-updates) hours and answers from its cache between checks.
|
||||
|
||||
If the update check fails (for example, no network), `update_available` and `latest_version` are `null` while `current_version` still reports the installed version.
|
||||
|
||||
| Status | Meaning |
|
||||
|
||||
+1
-4
@@ -37,10 +37,7 @@ def loopback_only(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatc
|
||||
def no_update_check(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Keep the release lookup of the health route off the network."""
|
||||
|
||||
async def no_release(*args: Any, **kwargs: Any) -> None:
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(UpdateChecker, "check_for_updates", no_release)
|
||||
monkeypatch.setattr(UpdateChecker, "check_for_updates_sync", lambda *args, **kwargs: None)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
@@ -121,6 +121,7 @@ def test_remote_get_tracks_scopes_server_cookies():
|
||||
service.__dict__.update(
|
||||
_tracks_by_title={},
|
||||
_chapters_by_title={},
|
||||
_title_alias={},
|
||||
_sample_decrypt_tracks=set(),
|
||||
_server_cdm=None,
|
||||
_session=requests.Session(),
|
||||
|
||||
@@ -223,7 +223,7 @@ async def health(request: web.Request) -> web.Response:
|
||||
nullable: true
|
||||
"""
|
||||
try:
|
||||
latest_version = await UpdateChecker.check_for_updates(__version__)
|
||||
latest_version = await asyncio.to_thread(UpdateChecker.check_for_updates_sync, __version__)
|
||||
update_info = {
|
||||
"update_available": latest_version is not None,
|
||||
"current_version": __version__,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
@@ -195,31 +194,6 @@ class UpdateChecker:
|
||||
except (ValueError, AttributeError):
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def check_for_updates(cls, current_version: str) -> Optional[str]:
|
||||
"""
|
||||
Examine GitHub for a newer version.
|
||||
|
||||
Args:
|
||||
current_version: The current version string (e.g., "1.1.0")
|
||||
|
||||
Returns:
|
||||
The latest version string if an update is available, None otherwise
|
||||
"""
|
||||
if not cls.is_valid_version(current_version):
|
||||
return None
|
||||
|
||||
try:
|
||||
latest_version = await asyncio.to_thread(cls.fetch_latest_version)
|
||||
|
||||
if latest_version and cls.compare_versions(current_version, latest_version):
|
||||
return latest_version
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_cached_update_info(cls, current_version: str) -> Optional[str]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user