From a1b4e884dab59f87899baa6252fa0bd4f9bce92c Mon Sep 17 00:00:00 2001 From: Claw Date: Tue, 17 Nov 2026 21:38:56 +0100 Subject: [PATCH] 0.12.0: FIFO job retention (job_keep), clear-finished button, vmm-ctl prune --- CHANGELOG.md | 4 ++++ README.md | 2 +- bin/vmm-ctl | 7 +++++++ bin/vmm-jobd | 5 +++++ bin/vmm-lib.php | 37 +++++++++++++++++++++++++++++++++++++ gui/ext/vmmngr/vmmngr.conf | 3 ++- gui/vmmngr_config.php | 9 +++++++++ gui/vmmngr_jobs.php | 17 +++++++++++++++++ version.txt | 2 +- 9 files changed, 83 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b756433..74177f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the VM Manager extension. +## 0.12.0 +- Job retention: finished jobs are pruned FIFO (default 100, configurable, + 0 = keep none), "Clear finished jobs" button, `vmm-ctl prune [n]`. + ## 0.11.0 - VM detail: configuration editor for vCPU, memory, loader, VNC, network switch and autostart (stopped guests only); writes `.conf` with a `.vmmngr.bak` backup and diff --git a/README.md b/README.md index d77fbee..97ae6eb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Status: **0.10.1** – feature-complete for daily use on a single node. | Switches | add/remove `manual` switches on existing host bridges, shows interface and IP | | Console | serial web terminal (ttyd, token URL) and graphical screen via noVNC/websockify | | Setup wizard | guided first run: prerequisites, default datastore, first switch | -| Jobs | every mutating action runs as a locked job with log; survives browser reloads | +| Jobs | every mutating action runs as a locked job with log; survives browser reloads; FIFO retention (default 100, clearable) | | Config | provider selection (`auto/system/bundle`), after-action behaviour, boot integration check | ## Requirements diff --git a/bin/vmm-ctl b/bin/vmm-ctl index 3af9d8a..02be136 100755 --- a/bin/vmm-ctl +++ b/bin/vmm-ctl @@ -185,6 +185,13 @@ switch ($cmd) { echo $d['ok'] ? "cancel requested\n" : ('error: ' . $d['error'] . "\n"); }); + case 'prune': + $keep = $arg !== '' ? (int)$arg : (int)(vmm_config()['job_keep'] ?? 100); + $res = vmm_job_prune($keep); + out($res, $json, static function (array $d): void { + printf("removed %d, kept %d\n", $d['removed'], $d['kept']); + }); + case 'recover': $fixed = vmm_job_recover(); out(['ok' => true, 'fixed' => $fixed], $json, static function (array $d): void { diff --git a/bin/vmm-jobd b/bin/vmm-jobd index 97f3481..0f7fdc0 100755 --- a/bin/vmm-jobd +++ b/bin/vmm-jobd @@ -269,4 +269,9 @@ joblog($log, sprintf('finished: rc=%d, state=%s', $rc, $stateAfter)); flock($lock, LOCK_UN); fclose($lock); fclose($log); + +// FIFO retention: keep only the configured number of finished jobs +$conf = vmm_config(); +vmm_job_prune((int)($conf['job_keep'] ?? 100)); + exit(0); diff --git a/bin/vmm-lib.php b/bin/vmm-lib.php index 29338de..9b16b63 100644 --- a/bin/vmm-lib.php +++ b/bin/vmm-lib.php @@ -34,6 +34,7 @@ function vmm_config(): array 'enable' => true, 'job_timeout' => 900, 'after_action' => 'stay', // stay | log + 'job_keep' => 100, // finished jobs to keep (0 = none) 'vm_dir_cache' => '', ]; if (!is_file(VMM_CONF)) { @@ -635,6 +636,42 @@ function vmm_job_list(int $limit = 50, string $vm = ''): array return $out; } +/** + * Delete old finished jobs (FIFO). Queued/running jobs are never touched. + * Returns ['removed' => int, 'kept' => int]. + */ +function vmm_job_prune(int $keep = 100, bool $onlyFinished = true): array +{ + vmm_ensure_state_dirs(); + $files = glob(VMM_JOBDIR . '/*.json') ?: []; + rsort($files); // newest first + $kept = 0; + $removed = 0; + foreach ($files as $i => $f) { + $job = json_decode((string)file_get_contents($f), true); + if (!is_array($job)) { + @unlink($f); + continue; + } + $state = (string)($job['state'] ?? ''); + $running = in_array($state, ['queued', 'running'], true); + if ($running) { + $kept++; + continue; + } + if ($kept < $keep) { + $kept++; + continue; + } + $id = (string)($job['id'] ?? basename($f, '.json')); + @unlink($f); + @unlink(VMM_JOBDIR . '/' . $id . '.log'); + @unlink(VMM_JOBDIR . '/' . $id . '.cancel'); + $removed++; + } + return ['removed' => $removed, 'kept' => $kept]; +} + function vmm_job_log(string $id, int $maxBytes = 65536): string { $f = VMM_JOBDIR . '/' . $id . '.log'; diff --git a/gui/ext/vmmngr/vmmngr.conf b/gui/ext/vmmngr/vmmngr.conf index 68f7721..0ecd376 100644 --- a/gui/ext/vmmngr/vmmngr.conf +++ b/gui/ext/vmmngr/vmmngr.conf @@ -1,6 +1,6 @@ { "appname": "VM Manager", - "version": "0.11.0", + "version": "0.12.0", "rootfolder": "/mnt/Daten/extensions/vmmngr", "vm_source": "auto", "bridges": ["ix0bridge"], @@ -8,5 +8,6 @@ "enable": true, "job_timeout": 900, "after_action": "stay", + "job_keep": 100, "ram_budget_pct": 85 } diff --git a/gui/vmmngr_config.php b/gui/vmmngr_config.php index 43dee82..08f9263 100644 --- a/gui/vmmngr_config.php +++ b/gui/vmmngr_config.php @@ -10,6 +10,8 @@ if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST $conf = vmm_config(); $conf['after_action'] = ($_POST['after_action'] ?? 'stay') === 'log' ? 'log' : 'stay'; $conf['vm_source'] = in_array($_POST['vm_source'] ?? '', ['auto', 'system', 'bundle'], true) ? $_POST['vm_source'] : 'auto'; + $keep = (int)($_POST['job_keep'] ?? 100); + $conf['job_keep'] = ($keep >= 0 && $keep <= 10000) ? $keep : 100; vmm_save_config($conf); $_SESSION['vmmngr_error'] = gettext('Settings saved.'); header('Location: vmmngr_config.php'); @@ -55,6 +57,13 @@ vmm_nav('config'); ?> + + + + + + + vm_source diff --git a/gui/vmmngr_jobs.php b/gui/vmmngr_jobs.php index 4124013..2fb51e5 100644 --- a/gui/vmmngr_jobs.php +++ b/gui/vmmngr_jobs.php @@ -5,6 +5,13 @@ require_once 'vmmngr-boot.inc'; +if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST['act'] ?? '') === 'clear_jobs') { + $res = vmm_job_prune(0); + $_SESSION['vmmngr_error'] = sprintf(gettext('Removed %d finished job(s).'), (int)$res['removed']); + header('Location: vmmngr_jobs.php'); + exit; +} + $pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Jobs')]; $id = (string)($_GET['id'] ?? ''); $job = $id !== '' ? vmm_job_get($id) : null; @@ -21,6 +28,10 @@ vmm_nav('jobs');
+ + + + @@ -52,6 +63,12 @@ vmm_nav('jobs');
+

+ + +

+
diff --git a/version.txt b/version.txt index d9df1bb..ac454c6 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.11.0 +0.12.0