1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +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

@ -10,7 +10,7 @@ from accounts.models import UserInstance
from computes.models import Compute
from instances.models import Instance
from operations import claims, jobs
from operations.models import Claim, Operation
from operations.models import Claim, Operation, WorkerLease
from operations.tests import fakes
from operations.utils import say
@ -68,6 +68,17 @@ class OperationsApiTestCase(TransactionTestCase):
self.client.force_login(stranger)
self.assertEqual(self.client.get("/api/v1/operations/resource/", {"key": "instance:u1"}).status_code, 404)
def test_the_server_says_whether_the_worker_is_gone(self):
# the job panel trusts this, not the browser's clock
self.client.force_login(self.owner)
def gone():
return self.client.get("/api/v1/operations/resource/", {"key": "instance:u2"}).json()["worker_gone"]
self.assertTrue(gone()) # no worker ever ran
WorkerLease.objects.create(name="worker", holder="h:1:a", host="h", heartbeat_at=timezone.now())
self.assertFalse(gone())
WorkerLease.objects.update(heartbeat_at=timezone.now() - timedelta(minutes=2))
self.assertTrue(gone())
def test_a_short_operation_is_flagged(self):
claims.admit({"instance:u2": Claim.EXCLUSIVE}, holder="another-request")
self.client.force_login(self.owner)