d7a58e52fd
lint / lint (push) Successful in 54s
test / integration-docker (pull_request) Successful in 38s
test / unit (pull_request) Successful in 45s
test / integration-firecracker (pull_request) Successful in 3m31s
test / coverage (pull_request) Successful in 18s
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Failing after 6s
Move the DbStore base (db_store), the shared schema-migration base (migrations / TableMigrations), the concrete stores (audit_store, config_store, queue_store), and StoreManager out of the package root into a bot_bottle/store/ package, so persistence lives in one place rather than scattered across the root. Callers use direct submodule imports (from bot_bottle.store.store_manager import StoreManager). Inside the moved modules the relative imports point back up to their non-store siblings (..paths, ..supervise_types) while co-moved siblings stay package-local; the flat-import fallbacks are untouched. The orchestrator's own stores (config_store, secret_store, registry) stay in orchestrator/ and repoint to the moved DbStore / TableMigrations. No behavior change; full unit suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Shared helpers for cached-image quickstart stale checks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
try:
|
|
from .store.config_store import ConfigStore
|
|
except ImportError:
|
|
from config_store import ConfigStore # type: ignore[import-not-found] # pylint: disable=import-error,no-name-in-module
|
|
|
|
|
|
class StaleImageError(Exception):
|
|
"""Raised when a cached image or artifact exceeds the configured staleness
|
|
threshold. Callers can catch this to prompt interactively; headless paths
|
|
let it propagate as a fatal error."""
|
|
|
|
|
|
def check_stale(label: str, created_at: datetime) -> None:
|
|
"""Raise StaleImageError if `created_at` is older than the configured
|
|
stale-warning threshold. Negative threshold disables the check."""
|
|
threshold_days = ConfigStore().cached_image_stale_warning_days()
|
|
if threshold_days < 0:
|
|
return
|
|
now = datetime.now(timezone.utc)
|
|
created = created_at.astimezone(timezone.utc)
|
|
age = now - created
|
|
if age.total_seconds() <= threshold_days * 86400:
|
|
return
|
|
raise StaleImageError(
|
|
f"cached {label} is {age.days} day(s) old; "
|
|
"quickstart does not verify it matches the current Dockerfile/context"
|
|
)
|
|
|
|
|
|
def check_stale_path(label: str, path: Path) -> None:
|
|
"""Raise StaleImageError if `path`'s mtime exceeds the staleness threshold."""
|
|
check_stale(label, datetime.fromtimestamp(path.stat().st_mtime, tz=timezone.utc))
|
|
|
|
|
|
__all__ = ["StaleImageError", "check_stale", "check_stale_path"]
|