Skip to content

Commit

Permalink
polling for experiment status
Browse files Browse the repository at this point in the history
  • Loading branch information
george-mzai committed Nov 19, 2024
1 parent 996730f commit 0d27923
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lumigator/frontend/src/services/health/healthService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import http from '@/services/http';
import { PATH_HEALTH_ROOT } from './api';
import { PATH_HEALTH_ROOT, PATH_HEALTH_JOB_METADATA } from './api';

async function fetchHealthStatus() {
try {
Expand All @@ -10,7 +10,17 @@ async function fetchHealthStatus() {
return error;
}
}
async function fetchJobStatus(id) {
try {
const response = await http.get(PATH_HEALTH_JOB_METADATA(id));
return response.data.status
} catch (error) {
console.log(error);
return error;
}
}

export default {
fetchHealthStatus,
}
fetchJobStatus
}
25 changes: 24 additions & 1 deletion lumigator/frontend/src/stores/health/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@ import healthService from "@/services/health/healthService";

export const useHealthStore = defineStore('health', () => {
const healthStatus = ref(null);
const runningJobs = ref([])

async function loadHealthStatus() {
healthStatus.value = await healthService.fetchHealthStatus();
}

async function updateJobStatus(jobId) {
try {
const status = await healthService.fetchJobStatus(jobId);
const job = runningJobs.value.find((job) => job.id === jobId);
if (job) {
job.status = status;
}
} catch (error) {
console.error(`Failed to update status for job ${jobId} ${error}`);
}
}

async function updateAllJobs() {
const promises = runningJobs.value
// Skip jobs that are complete or failed
.filter((job) => job.status === 'RUNNING' || job.status === 'created')
.map((job) => updateJobStatus(job.id));
await Promise.all(promises);
}

return {
healthStatus,
updateAllJobs,
runningJobs,
loadHealthStatus
}

})
})

0 comments on commit 0d27923

Please sign in to comment.