mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 12:54:31 +00:00
Resume interrupted WebDAV cache builds without resetting completed stages
This commit is contained in:
@@ -185,7 +185,7 @@ function bratonien_tools_start_webdav_warmup_mode($mode, $message)
|
|||||||
'queued',
|
'queued',
|
||||||
$mode === 'rebuild'
|
$mode === 'rebuild'
|
||||||
? 'Cache-Rebuild wurde angefordert. Der Worker wartet auf den Start und gleicht danach Shadow-Tree und eigenen Index ab.'
|
? 'Cache-Rebuild wurde angefordert. Der Worker wartet auf den Start und gleicht danach Shadow-Tree und eigenen Index ab.'
|
||||||
: 'Quellenprüfung wurde angefordert. Der Worker wartet auf den Start und gleicht danach Shadow-Tree und eigenen Index ab.',
|
: 'Cache-Fortsetzung wurde angefordert. Bereits erfolgreich abgeschlossene Stufen bleiben erhalten; verarbeitet werden nur noch fehlende oder geänderte Quellen.',
|
||||||
array('mode'=>$mode, 'run_id'=>$run_id)
|
array('mode'=>$mode, 'run_id'=>$run_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ function bratonien_tools_start_webdav_warmup_manual()
|
|||||||
{
|
{
|
||||||
return bratonien_tools_start_webdav_warmup_mode(
|
return bratonien_tools_start_webdav_warmup_mode(
|
||||||
'manual',
|
'manual',
|
||||||
'WebDAV-Worker: Shadow-Tree wird mit dem eigenen Index auf neue oder geänderte Quellen abgeglichen.'
|
'WebDAV-Worker: Shadow-Tree wird mit dem eigenen Index auf neue, geänderte oder noch nicht vollständig verarbeitete Quellen abgeglichen.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +224,29 @@ function bratonien_tools_start_webdav_cache_rebuild()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_webdav_cache_build_should_resume()
|
||||||
|
{
|
||||||
|
$now = time();
|
||||||
|
foreach (bratonien_tools_webdav_warmup_connections() as $connection_id=>$runtime)
|
||||||
|
{
|
||||||
|
$file = bratonien_tools_webdav_warmup_status_file_for_connection($connection_id);
|
||||||
|
if (!is_file($file) || !is_readable($file)) continue;
|
||||||
|
$raw = @file_get_contents($file);
|
||||||
|
$status = $raw !== false ? json_decode($raw, true) : null;
|
||||||
|
if (!is_array($status)) continue;
|
||||||
|
|
||||||
|
$state = (string)($status['state'] ?? 'idle');
|
||||||
|
if (in_array($state, array('preempted','error','fatal'), true)) return true;
|
||||||
|
|
||||||
|
if (in_array($state, array('queued','scan','running'), true))
|
||||||
|
{
|
||||||
|
$updated = (int)($status['updated_at'] ?? 0);
|
||||||
|
if ($updated > 0 && ($now - $updated) > 120) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_has_local_cache_sources()
|
function bratonien_tools_has_local_cache_sources()
|
||||||
{
|
{
|
||||||
if (!function_exists('bratonien_tools_webdav_materialize_source_info')) return true;
|
if (!function_exists('bratonien_tools_webdav_materialize_source_info')) return true;
|
||||||
@@ -240,10 +263,17 @@ function bratonien_tools_has_local_cache_sources()
|
|||||||
|
|
||||||
function bratonien_tools_start_combined_image_cache_build()
|
function bratonien_tools_start_combined_image_cache_build()
|
||||||
{
|
{
|
||||||
// Der WebDAV-Status muss vor jedem asynchronen Start auf queued wechseln.
|
// Ein unvollständiger WebDAV-Lauf wird fortgesetzt. Nur wenn kein
|
||||||
// Sonst kann die Admin-Seite den complete-Status des vorigen Laufs sofort
|
// fortsetzbarer Lauf existiert, startet der Button einen echten Rebuild.
|
||||||
// als Ergebnis des neuen Klicks interpretieren und die Abfrage beenden.
|
// Dadurch bleiben bereits gesetzte stage1/stage2-Signaturen erhalten und
|
||||||
$webdav = bratonien_tools_start_webdav_cache_rebuild();
|
// ein Abbruch nach Stufe 1 führt nicht erneut zu einem Start bei 0.
|
||||||
|
$resume = bratonien_tools_webdav_cache_build_should_resume();
|
||||||
|
$webdav = $resume
|
||||||
|
? bratonien_tools_start_webdav_warmup_mode(
|
||||||
|
'manual',
|
||||||
|
'WebDAV-Bildcache: unterbrochener Lauf wird aus dem vorhandenen Worker-Index fortgesetzt; fertige Stufen werden nicht erneut verarbeitet.'
|
||||||
|
)
|
||||||
|
: bratonien_tools_start_webdav_cache_rebuild();
|
||||||
$main = array('started'=>false, 'message'=>'');
|
$main = array('started'=>false, 'message'=>'');
|
||||||
|
|
||||||
if (bratonien_tools_has_local_cache_sources())
|
if (bratonien_tools_has_local_cache_sources())
|
||||||
|
|||||||
Reference in New Issue
Block a user