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 document.getElementById('job_state').innerText = data.state; if (data.state == "error") { document.getElementById('job_error').innerText = data.error; stopPolling(); } if (data.state == "done") { stopPolling(); } } catch (error) { console.error(error); } }; function stopPolling() { clearInterval(pollingIntervalId) } // Poll the endpoint every 5 seconds (adjust as needed) const pollingInterval = 2000; //ms const pollingIntervalId = setInterval(fetchJobState, pollingInterval); // Initial fetch fetchJobState();