Skip to content

Commit

Permalink
Merge pull request #89 from ceph/job-history
Browse files Browse the repository at this point in the history
  • Loading branch information
zmc authored Nov 20, 2024
2 parents b36478f + b64cff6 commit 9a03741
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/components/JobHistory/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import JobList from "../JobList";
import { useJobHistory } from "../../lib/paddles";
import { Button, Typography, Box } from "@mui/material";


const pageSize = 25;

export default function JobHistory({description}) {
if (!description) {
return null;
}

const jobHistoryQuery = useJobHistory(description, pageSize);

return (
<Box sx={{ padding: '0px 8px' }}>
<Typography variant="body1" margin={"10px 0px"}>
Past {pageSize} jobs with same description:
</Typography>
<JobList query={jobHistoryQuery} sortMode="time" />
</Box>
);
}
4 changes: 2 additions & 2 deletions src/components/JobList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { type Theme } from "@mui/material/styles";
import { formatDate, formatDuration } from "../../lib/utils";
import IconLink from "../../components/IconLink";
import Link from "../../components/Link";
import type { Job, NodeJobs, Run } from "../../lib/paddles.d";
import type { Job, JobList, Run } from "../../lib/paddles.d";
import { dirName } from "../../lib/utils";
import useDefaultTableOptions from "../../lib/table";

Expand Down Expand Up @@ -220,7 +220,7 @@ function JobDetailPanel(props: JobDetailPanelProps): ReactNode {
};

type JobListProps = {
query: UseQueryResult<Run> | UseQueryResult<NodeJobs>;
query: UseQueryResult<Run> | UseQueryResult<JobList>;
sortMode?: "time" | "id";
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/paddles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type Node = {
machine_type: string;
};

export type NodeJobs = {
export type JobList = {
jobs?: Job[];
}

Expand Down
26 changes: 23 additions & 3 deletions src/lib/paddles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { UseQueryResult } from "@tanstack/react-query";
import type {
GetURLParams,
Run, Job,
Node, NodeJobs,
Node, JobList,
StatsLocksResponse,
StatsJobsResponse,
} from "./paddles.d";
Expand Down Expand Up @@ -40,6 +40,8 @@ function getURL(endpoint: string, params?: GetURLParams) {
uri += "queued/";
delete params_[key];
break;
case "description":
break;
case "machine_type":
break;
default:
Expand Down Expand Up @@ -106,7 +108,24 @@ function useMachineTypes() {
});
}

function useNodeJobs(name: string, params: GetURLParams): UseQueryResult<NodeJobs> {
function useJobHistory(description: string, pageSize: number): UseQueryResult<JobList> {
const url = getURL(`/jobs/`, { 'description': description, "pageSize": pageSize });
const query = useQuery(["job-history", { url }], {
select: (data: Job[]) => {
data.forEach((item) => {
item.id = item.job_id + "";
});
const resp: JobList = { 'jobs': data }
return resp;
},
cacheTime: 60 * 60,
staleTime: 60 * 60,
retry: 1,
});
return query;
}

function useNodeJobs(name: string, params: GetURLParams): UseQueryResult<JobList> {
// 'page' and 'count' are mandatory query params for this paddles endpoint
params = { "page": params?.page || 0, "pageSize": params?.pageSize || 25 }
const url = getURL(`/nodes/${name}/jobs/`, params);
Expand All @@ -115,7 +134,7 @@ function useNodeJobs(name: string, params: GetURLParams): UseQueryResult<NodeJob
data.forEach((item) => {
item.id = item.job_id + "";
});
const resp: NodeJobs = { 'jobs': data }
const resp: JobList = { 'jobs': data }
return resp;
},
});
Expand Down Expand Up @@ -235,4 +254,5 @@ export {
useNodes,
useStatsNodeLocks,
useStatsNodeJobs,
useJobHistory,
};
13 changes: 13 additions & 0 deletions src/pages/Job/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Typography from "@mui/material/Typography";
import Accordion from "@mui/material/Accordion";
import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails";
import Button from "@mui/material/Button";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ScheduleIcon from "@mui/icons-material/Schedule";
import PlayCircleOutlineIcon from "@mui/icons-material/PlayCircleOutline";
Expand All @@ -21,6 +22,8 @@ import Link from "../../components/Link";
import CodeBlock from "../../components/CodeBlock";
import { useJob } from "../../lib/paddles";
import { getDuration, dirName } from "../../lib/utils";
import JobHistory from "../../components/JobHistory";
import { useState } from "react";

function StatusIcon({ status }) {
const theme = useTheme();
Expand Down Expand Up @@ -155,6 +158,7 @@ function JobDetails({ query }) {
export default function Job() {
const { name, job_id } = useParams();
const query = useJob(name, job_id);
const [showJobHistory, toggleShowJobHistory] = useState(false);
return (
<Grid container spacing={2}>
<Helmet>
Expand All @@ -173,6 +177,15 @@ export default function Job() {
<JobDetails query={query} />
</AccordionDetails>
</Accordion>
<Button variant={"text"} sx={{"marginTop": "10px"}}
onClick={() => toggleShowJobHistory(!showJobHistory)}>
{showJobHistory ? "Hide": "Show"} history
</Button>
{ showJobHistory ?
(query.data?.description ? <JobHistory description={query.data.description} /> : null)
:null
}

</Grid>
</Grid>
);
Expand Down

0 comments on commit 9a03741

Please sign in to comment.