SpeedyF/static/checkjob.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-05-01 13:39:29 +01:00
console.log("jobId: ", job_id)
const fetchJobState = async () => {
try {
const response = await fetch(`/job_state?job_id=${job_id}`);
if (!response.ok) {
throw new Error('Failed to fetch job state');
}
const data = await response.json();
// Update UI with job state
2024-05-01 14:10:26 +01:00
document.getElementById('state-msg').innerText = data.state;
2024-05-01 13:39:29 +01:00
if (data.state == "error") {
document.getElementById('job_error').innerText = data.error;
2024-05-01 14:10:26 +01:00
document.getElementById('err_msg').style = 'display: inline-block;'
2024-05-01 13:39:29 +01:00
stopPolling();
}
if (data.state == "done") {
stopPolling();
2024-05-01 14:10:26 +01:00
showDownloadButton();
document.title = "All Done"
document.getElementById('title').textContent = "All Done"
2024-05-01 13:39:29 +01:00
}
} catch (error) {
console.error(error);
}
};
function stopPolling() {
clearInterval(pollingIntervalId)
}
2024-05-01 14:10:26 +01:00
function showDownloadButton() {
document.getElementById('download-button').style = 'display: inline-block;'
}
2024-05-01 13:39:29 +01:00
// Poll the endpoint every 5 seconds (adjust as needed)
const pollingInterval = 2000; //ms
const pollingIntervalId = setInterval(fetchJobState, pollingInterval);
// Initial fetch
fetchJobState();