feat(monitoring): add update-run log, fix scheduler skipping stale customer containers
The automatic scheduler only recreated customer containers when it had just found a NEW image on Docker Hub. If an image was already pulled locally (e.g. from an earlier manual pull, or auto-apply was off at the time) but customer containers hadn't been recreated yet, the daily check reported "already up to date" and silently never touched those customers again — the recreate step needs to run independently of whether Hub had anything new, based on each customer's actual container-vs-local-image state. Also adds a persistent UpdateRunLog: every scheduled and manual pull/update run now records per-image pull results and per-customer recreate results, visible in Monitoring > Update Log, instead of only existing in container logs.
This commit is contained in:
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
||||
from app.database import SessionLocal, get_db
|
||||
from app.dependencies import get_current_user
|
||||
from app.models import Customer, Deployment, SystemConfig, User
|
||||
from app.services import docker_service, image_service, netbird_client_update_service, netbird_service
|
||||
from app.services import docker_service, image_service, netbird_client_update_service, netbird_service, update_log_service
|
||||
from app.utils.security import decrypt_value, encrypt_value
|
||||
from app.utils.validators import NetbirdApiTokenPayload, NetbirdClientAutoUpdatePayload
|
||||
|
||||
@@ -246,9 +246,18 @@ async def update_customer_images(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="System not configured."
|
||||
)
|
||||
|
||||
started_at = datetime.utcnow()
|
||||
instance_dir = f"{config.data_dir}/{customer.subdomain}"
|
||||
result = await image_service.update_customer_containers(instance_dir, deployment.container_prefix)
|
||||
|
||||
update_log_service.record_run(
|
||||
db, run_type="manual", trigger=current_user.username, started_at=started_at,
|
||||
apply_attempted=True,
|
||||
customer_results=[{
|
||||
"customer_name": customer.name, "success": result["success"], "error": result.get("error"),
|
||||
}],
|
||||
)
|
||||
|
||||
if not result["success"]:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user