1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix: worker warnings and CPU windows do not depend on a wall clock

The job panel warned "Worker unavailable" when the worker's last
heartbeat was more than 60 s older than the browser's clock: a browser
set two minutes ahead warned about a worker that had just beaten, and
one behind hid a worker that had stopped. The server now says whether
the worker is gone (worker_gone in the job panel's answer), by the same
rule as the Jobs page.

A host's CPU graph measured its averaging window with time.time(): a
clock set back between two polls gave a negative window. It now uses
time.monotonic(), as a VM's usage already does; a sample from before
the server restarted is measured over a second again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-10 11:57:43 +03:00
parent 25e49c2aa2
commit e83bdcbd44
9 changed files with 55 additions and 21 deletions

View file

@ -1,4 +1,3 @@
from datetime import timedelta
from urllib.parse import urlencode
from django.contrib import messages
@ -6,14 +5,13 @@ from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator
from django.http import Http404
from django.shortcuts import redirect, render
from django.utils import timezone
from django.utils.translation import gettext as _
from django.views.decorators.http import require_POST
from vrtManager.util import OperationError
from . import jobs as jobs_module
from .api.serializers import OperationSerializer
from .models import Operation, last_seen
from .models import Operation, last_seen, worker_gone
from .utils import said, words
@ -44,7 +42,7 @@ def jobs(request):
rows = [(op, OperationSerializer(op, context={"request": request}).data) for op in page.object_list]
seen = last_seen()
# a job the worker has to start, run or stop, not one a request runs (job_panel.js uses the same rule)
unavailable = ((seen is None or timezone.now() - seen > timedelta(seconds=60))
unavailable = (worker_gone(seen)
and _visible(request.user).filter(state__in=Operation.ACTIVE)
.exclude(worker=Operation.REQUEST).exists())
return render(request, "operations/jobs.html",