0.12.0: FIFO job retention (job_keep), clear-finished button, vmm-ctl prune

This commit is contained in:
Claw committed 2026-11-17 21:38:56 +01:00
1 parent 5dc6bfb5a2
commit a1b4e884da
9 files changed
+83 -3

No files matched your search

+4
View File
@@ -2,6 +2,10 @@
All notable changes to the VM Manager extension. 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 ## 0.11.0
- VM detail: configuration editor for vCPU, memory, loader, VNC, network switch and - VM detail: configuration editor for vCPU, memory, loader, VNC, network switch and
autostart (stopped guests only); writes `<vm>.conf` with a `.vmmngr.bak` backup and autostart (stopped guests only); writes `<vm>.conf` with a `.vmmngr.bak` backup and
+1 -1
View File
@@ -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 | | 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 | | Console | serial web terminal (ttyd, token URL) and graphical screen via noVNC/websockify |
| Setup wizard | guided first run: prerequisites, default datastore, first switch | | 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 | | Config | provider selection (`auto/system/bundle`), after-action behaviour, boot integration check |
## Requirements ## Requirements
+7
View File
@@ -185,6 +185,13 @@ switch ($cmd) {
echo $d['ok'] ? "cancel requested\n" : ('error: ' . $d['error'] . "\n"); 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': case 'recover':
$fixed = vmm_job_recover(); $fixed = vmm_job_recover();
out(['ok' => true, 'fixed' => $fixed], $json, static function (array $d): void { out(['ok' => true, 'fixed' => $fixed], $json, static function (array $d): void {
+5
View File
@@ -269,4 +269,9 @@ joblog($log, sprintf('finished: rc=%d, state=%s', $rc, $stateAfter));
flock($lock, LOCK_UN); flock($lock, LOCK_UN);
fclose($lock); fclose($lock);
fclose($log); 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); exit(0);
+37
View File
@@ -34,6 +34,7 @@ function vmm_config(): array
'enable' => true, 'enable' => true,
'job_timeout' => 900, 'job_timeout' => 900,
'after_action' => 'stay', // stay | log 'after_action' => 'stay', // stay | log
'job_keep' => 100, // finished jobs to keep (0 = none)
'vm_dir_cache' => '', 'vm_dir_cache' => '',
]; ];
if (!is_file(VMM_CONF)) { if (!is_file(VMM_CONF)) {
@@ -635,6 +636,42 @@ function vmm_job_list(int $limit = 50, string $vm = ''): array
return $out; 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 function vmm_job_log(string $id, int $maxBytes = 65536): string
{ {
$f = VMM_JOBDIR . '/' . $id . '.log'; $f = VMM_JOBDIR . '/' . $id . '.log';
+2 -1
View File
@@ -1,6 +1,6 @@
{ {
"appname": "VM Manager", "appname": "VM Manager",
"version": "0.11.0", "version": "0.12.0",
"rootfolder": "/mnt/Daten/extensions/vmmngr", "rootfolder": "/mnt/Daten/extensions/vmmngr",
"vm_source": "auto", "vm_source": "auto",
"bridges": ["ix0bridge"], "bridges": ["ix0bridge"],
@@ -8,5 +8,6 @@
"enable": true, "enable": true,
"job_timeout": 900, "job_timeout": 900,
"after_action": "stay", "after_action": "stay",
"job_keep": 100,
"ram_budget_pct": 85 "ram_budget_pct": 85
} }
+9
View File
@@ -10,6 +10,8 @@ if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST
$conf = vmm_config(); $conf = vmm_config();
$conf['after_action'] = ($_POST['after_action'] ?? 'stay') === 'log' ? 'log' : 'stay'; $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'; $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); vmm_save_config($conf);
$_SESSION['vmmngr_error'] = gettext('Settings saved.'); $_SESSION['vmmngr_error'] = gettext('Settings saved.');
header('Location: vmmngr_config.php'); header('Location: vmmngr_config.php');
@@ -55,6 +57,13 @@ vmm_nav('config'); ?>
<button type="submit" class="formbtn" name="act" value="save_settings" style="margin-left:8px;"><?=gettext('Save');?></button> <button type="submit" class="formbtn" name="act" value="save_settings" style="margin-left:8px;"><?=gettext('Save');?></button>
</td> </td>
</tr> </tr>
<tr>
<td class="celltag"><?=gettext('Job retention');?></td>
<td class="celldata">
<input type="text" name="job_keep" size="6" value="<?=(int)($conf['job_keep'] ?? 100);?>"/>
<span style="opacity:.75;margin-left:8px;"><?=gettext('finished jobs to keep (FIFO); 0 = delete after each run');?></span>
</td>
</tr>
<tr> <tr>
<td class="celltag">vm_source</td> <td class="celltag">vm_source</td>
<td class="celldata"> <td class="celldata">
+17
View File
@@ -5,6 +5,13 @@
require_once 'vmmngr-boot.inc'; 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')]; $pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Jobs')];
$id = (string)($_GET['id'] ?? ''); $id = (string)($_GET['id'] ?? '');
$job = $id !== '' ? vmm_job_get($id) : null; $job = $id !== '' ? vmm_job_get($id) : null;
@@ -21,6 +28,10 @@ vmm_nav('jobs');
<form action="vmmngr_jobs.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame"> <form action="vmmngr_jobs.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
<?php endif; ?>
<?php if ($job !== null): ?> <?php if ($job !== null): ?>
<table class="area_data_settings" style="width:100%;border-collapse:collapse;"> <table class="area_data_settings" style="width:100%;border-collapse:collapse;">
<colgroup> <colgroup>
@@ -52,6 +63,12 @@ vmm_nav('jobs');
<br /> <br />
<?php endif; ?> <?php endif; ?>
<p>
<button type="submit" class="formbtn" name="act" value="clear_jobs"
onclick="return confirm('Remove all finished jobs? Running jobs are kept.')"><?=gettext('Clear finished jobs');?></button>
<span style="opacity:.75;margin-left:8px;"><?=gettext('Retention keeps the newest %d jobs automatically (Configuration).', (int)(vmm_config()['job_keep'] ?? 100));?></span>
</p>
<table class="area_data_selection" style="width:100%;border-collapse:collapse;"> <table class="area_data_selection" style="width:100%;border-collapse:collapse;">
<colgroup> <colgroup>
<col style="width:26%"> <col style="width:26%">
+1 -1
View File
@@ -1 +1 @@
0.11.0 0.12.0