Skip to content

Commit

Permalink
on job list page, refresh submitted jobs until all are complete
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Jan 23, 2024
1 parent 1763215 commit 6aec0dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/components/JobDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function JobDetail(props) {
);
const intervalID = setInterval(() => {
if (revalidator.state === "idle") {
console.log("Refreshing page");
revalidator.revalidate();
}
}, 5000);
Expand Down
19 changes: 16 additions & 3 deletions src/components/JobList.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext, useEffect, useState, Fragment } from "react";
import { Link } from "react-router-dom";
import { useEffect, useState, Fragment } from "react";
import { Link, useRevalidator } from "react-router-dom";

import {
Button,
Expand Down Expand Up @@ -29,7 +29,7 @@ import {
import StatusChip from "./StatusChip";

import { DELTA_JOBS } from "../globals";
import { timeFormat } from "../utils";
import { jobIsIncomplete, timeFormat } from "../utils";

function filterJobs(jobs, statusFilter, hardwareFilter, tagFilter) {
function hasStatus(job) {
Expand Down Expand Up @@ -96,8 +96,21 @@ function JobList(props) {
let [statusFilter, setStatusFilter] = useState("");
let [hardwareFilter, setHardwareFilter] = useState("");
let [tagFilter, setTagFilter] = useState("");
let revalidator = useRevalidator();

useEffect(() => {
const incompleteJobs = props.jobs.filter((job) => jobIsIncomplete(job));
if (incompleteJobs.length > 0 && revalidator.state === "idle") {
console.log(
"There are submitted or running jobs, page will refresh every 5 seconds until all jobs are complete"
);
const intervalID = setInterval(() => {
if (revalidator.state === "idle") {
revalidator.revalidate();
}
}, 5000);
return () => clearInterval(intervalID);
}
setFilteredJobs(filterJobs(props.jobs, statusFilter, hardwareFilter, tagFilter));
}, [props.jobs, statusFilter, hardwareFilter, tagFilter]);

Expand Down
5 changes: 5 additions & 0 deletions src/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ async function queryJobs(collab, auth, requestedSize) {
jobArray.sort((a, b) => {
return b.id - a.id; // sort by descending order of job id
});
// for incomplete jobs, check if they've completed
const incompleteJobs = jobArray.filter((job) => jobIsIncomplete(job));
for (const job of incompleteJobs) {
getJob(job.id, collab, auth);
}
return jobArray.slice(0, size);
}

Expand Down

0 comments on commit 6aec0dd

Please sign in to comment.