mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 23:41:28 +00:00
Merge pull request #16 from MrSleeps/fix/live-job-status-polling
Keep plugin and web job status in sync
This commit is contained in:
@@ -109,6 +109,8 @@
|
||||
var currentConfig = null;
|
||||
var statusTimer = null;
|
||||
var captionTimer = null;
|
||||
var lastIndexRunning = false;
|
||||
var lastCaptionRunning = false;
|
||||
var lastCaptionStatus = null;
|
||||
|
||||
function selectedLibraryIds() {
|
||||
@@ -198,16 +200,13 @@
|
||||
function refreshStatus() {
|
||||
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/IndexStatus'))
|
||||
.then(function (status) {
|
||||
var running = !!(status && status.running);
|
||||
renderStatus(status);
|
||||
if (status && status.running) {
|
||||
if (!statusTimer) {
|
||||
statusTimer = setInterval(refreshStatus, 2000);
|
||||
}
|
||||
} else if (statusTimer) {
|
||||
clearInterval(statusTimer);
|
||||
statusTimer = null;
|
||||
|
||||
if (lastIndexRunning && !running) {
|
||||
loadLibraries();
|
||||
}
|
||||
lastIndexRunning = running;
|
||||
})
|
||||
.catch(function () {
|
||||
renderStatus(null);
|
||||
@@ -314,15 +313,9 @@
|
||||
function refreshCaptionStatus() {
|
||||
return ApiClient.getJSON(ApiClient.getUrl('Plugins/SceneSearch/CaptionStatus'))
|
||||
.then(function (status) {
|
||||
var running = !!(status && status.running);
|
||||
renderCaptionStatus(status);
|
||||
if (status && status.running) {
|
||||
if (!captionTimer) {
|
||||
captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
}
|
||||
} else if (captionTimer) {
|
||||
clearInterval(captionTimer);
|
||||
captionTimer = null;
|
||||
}
|
||||
lastCaptionRunning = running;
|
||||
})
|
||||
.catch(function () {
|
||||
renderCaptionStatus(null);
|
||||
@@ -351,6 +344,13 @@
|
||||
page.querySelector('#timeoutSeconds').value = config.TimeoutSeconds || 60;
|
||||
|
||||
return Promise.all([loadLibraries(), refreshStatus(), refreshCaptionStatus()]);
|
||||
}).then(function () {
|
||||
if (!statusTimer) {
|
||||
statusTimer = setInterval(refreshStatus, 2000);
|
||||
}
|
||||
if (!captionTimer) {
|
||||
captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
}
|
||||
}).finally(function () {
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
@@ -400,6 +400,9 @@
|
||||
});
|
||||
}).then(function () {
|
||||
refreshStatus();
|
||||
if (!statusTimer) {
|
||||
statusTimer = setInterval(refreshStatus, 2000);
|
||||
}
|
||||
}).catch(function () {
|
||||
page.querySelector('#indexStatus').textContent =
|
||||
'Could not start indexing. Check Jellyfin logs and Scene Search API status.';
|
||||
@@ -431,6 +434,9 @@
|
||||
});
|
||||
}).then(function () {
|
||||
refreshCaptionStatus();
|
||||
if (!captionTimer) {
|
||||
captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
}
|
||||
}).catch(function () {
|
||||
page.querySelector('#captionStatus').textContent =
|
||||
'Could not start captioning. Check Jellyfin logs and Scene Search API status.';
|
||||
|
||||
+18
-18
@@ -123,6 +123,8 @@
|
||||
const $ = id => document.getElementById(id);
|
||||
let statusTimer = null;
|
||||
let captionTimer = null;
|
||||
let lastIndexRunning = false;
|
||||
let lastCaptionRunning = false;
|
||||
let captionLastStatus = null;
|
||||
let thumbnailUrls = [];
|
||||
|
||||
@@ -222,13 +224,13 @@
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const s = await api('/api/jellyfin/index/status');
|
||||
const running = !!s.running;
|
||||
renderStatus(s);
|
||||
if (!s.running && statusTimer) {
|
||||
clearInterval(statusTimer);
|
||||
statusTimer = null;
|
||||
if (lastIndexRunning && !running) {
|
||||
loadLibraries();
|
||||
refreshHealth();
|
||||
}
|
||||
lastIndexRunning = running;
|
||||
return s;
|
||||
} catch (e) {
|
||||
$('indexStatus').className = 'status error';
|
||||
@@ -250,6 +252,7 @@
|
||||
body:JSON.stringify({library_ids:ids, force:$('forceIndex').checked})
|
||||
});
|
||||
renderStatus(s);
|
||||
lastIndexRunning = !!s.running;
|
||||
if (!statusTimer) statusTimer = setInterval(refreshStatus, 2000);
|
||||
} catch (e) {
|
||||
$('indexStatus').className = 'status error';
|
||||
@@ -324,14 +327,12 @@
|
||||
async function refreshCaptionStatus() {
|
||||
try {
|
||||
const s = await api('/api/caption/status');
|
||||
const running = !!s.running;
|
||||
renderCaptionStatus(s);
|
||||
if (s.running) {
|
||||
if (!captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
} else if (captionTimer) {
|
||||
clearInterval(captionTimer);
|
||||
captionTimer = null;
|
||||
if (lastCaptionRunning && !running) {
|
||||
refreshHealth();
|
||||
}
|
||||
lastCaptionRunning = running;
|
||||
return s;
|
||||
} catch (e) {
|
||||
$('captionStatus').className = 'status error';
|
||||
@@ -353,7 +354,8 @@
|
||||
body:JSON.stringify({library_ids:ids, force:$('forceCaption').checked})
|
||||
});
|
||||
renderCaptionStatus(s);
|
||||
if (s.running && !captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
lastCaptionRunning = !!s.running;
|
||||
if (!captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
} catch (e) {
|
||||
$('captionStatus').className = 'status error';
|
||||
$('captionStatus').textContent = e.message;
|
||||
@@ -426,11 +428,11 @@
|
||||
|
||||
$('saveKey').onclick = () => {
|
||||
localStorage.setItem('sceneSearchApiKey', $('apiKey').value.trim());
|
||||
loadLibraries(); refreshStatus(); refreshCaptionStatus();
|
||||
window.location.reload();
|
||||
};
|
||||
$('clearKey').onclick = () => {
|
||||
localStorage.removeItem('sceneSearchApiKey'); $('apiKey').value = '';
|
||||
loadLibraries(); refreshStatus(); refreshCaptionStatus();
|
||||
localStorage.removeItem('sceneSearchApiKey');
|
||||
window.location.reload();
|
||||
};
|
||||
$('refreshLibraries').onclick = loadLibraries;
|
||||
$('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true);
|
||||
@@ -442,12 +444,10 @@
|
||||
|
||||
refreshHealth();
|
||||
loadLibraries();
|
||||
refreshStatus().then(s => {
|
||||
if (s && s.running && !statusTimer) statusTimer = setInterval(refreshStatus, 2000);
|
||||
});
|
||||
refreshCaptionStatus().then(s => {
|
||||
if (s && s.running && !captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
});
|
||||
refreshStatus();
|
||||
refreshCaptionStatus();
|
||||
statusTimer = setInterval(refreshStatus, 2000);
|
||||
captionTimer = setInterval(refreshCaptionStatus, 2000);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user