Skip to content

Commit

Permalink
Merge pull request #449 from DataRecce/feature/drc-769-in-history-pan…
Browse files Browse the repository at this point in the history
…e-update-the-running-status-if-a-run-is-still

[Enhancement] in history list, update the running status if a run is still running
  • Loading branch information
popcornylu authored Oct 14, 2024
2 parents 7129ab2 + 675c70c commit ce73702
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
1 change: 1 addition & 0 deletions js/src/components/check/StateImporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function StateImporter() {
const { runs, checks } = await importState(selectedFile);
refetchRunsAggregated();
await queryClient.invalidateQueries({ queryKey: cacheKeys.checks() });
await queryClient.invalidateQueries({ queryKey: cacheKeys.runs() });
if (location.includes("/checks")) {
setLocation("/checks");
}
Expand Down
1 change: 1 addition & 0 deletions js/src/components/check/StateSynchronizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function StateSynchronizer() {

queryClient.invalidateQueries({ queryKey: cacheKeys.lineage() });
queryClient.invalidateQueries({ queryKey: cacheKeys.checks() });
queryClient.invalidateQueries({ queryKey: cacheKeys.runs() });

if (isCheckDetailPage(location)) {
setLocation("/checks");
Expand Down
56 changes: 35 additions & 21 deletions js/src/components/run/RunList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Tooltip,
Heading,
Center,
Spinner,
} from "@chakra-ui/react";
import { cacheKeys } from "@/lib/api/cacheKeys";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
Expand All @@ -21,7 +22,7 @@ import { TbChecklist } from "react-icons/tb";
import { IconType } from "react-icons";
import { findByRunType } from "../run/registry";
import { Run } from "@/lib/api/types";
import { listRuns } from "@/lib/api/runs";
import { listRuns, waitRun } from "@/lib/api/runs";
import { useRecceActionContext } from "@/lib/hooks/RecceActionContext";
import { format, formatDistanceToNow } from "date-fns";
import { RepeatIcon } from "@chakra-ui/icons";
Expand All @@ -30,36 +31,53 @@ import SimpleBar from "simplebar-react";
import "simplebar/dist/simplebar.min.css";

const RunListItemStatus = ({ run }: { run: Run }) => {
let status: string | undefined = run.status;
const { data: fetchedRun } = useQuery({
queryKey: cacheKeys.run(run.run_id),
queryFn: async () => {
return await waitRun(run.run_id);
},
enabled: run?.status === "running",
retry: false,
});
const isRunning = fetchedRun
? fetchedRun.status === "running"
: run?.status === "running";

let status: string | undefined = fetchedRun?.status || run?.status;
if (!status) {
if (run.result) {
status = "successful";
status = "finished";
} else if (run.error) {
status = "failed";
}
}

let color = "";
let message = "";
if (status === "successful") {
if (status === "successful" || status === "finished") {
color = "green";
message = "Successful";
message = "Finished";
} else if (status === "failed") {
color = "red";
message = "Failed";
} else if (status === "cancelled") {
color = "gray";
message = "Cancelled";
} else if (status === "running") {
color = "blue";
message = "Running";
} else {
color = "gray";
message = "Unknown";
color = "green";
message = "Finished";
}

status === "successful" ? "green" : status === "failed" ? "red" : "gray";
return (
<Text fontWeight={500} color={`${color}.400`}>
{message}
</Text>
<>
{isRunning && <Spinner size="xs" color={`${color}.400`} />}
<Text fontWeight={500} color={`${color}.400`}>
{message}
</Text>
</>
);
};

Expand Down Expand Up @@ -106,10 +124,11 @@ const RunListItem = ({
textOverflow="ellipsis"
whiteSpace="nowrap"
overflow="hidden"
color={run.name ? "inherit" : "gray.500"}
fontSize="11pt"
fontWeight="500"
>
{run.name}
{run.name || "<no name>"}
</Box>
{checkId ? (
<Tooltip label="Go to Check" aria-label="Go to Check">
Expand Down Expand Up @@ -139,19 +158,13 @@ const RunListItem = ({
</Flex>
<Flex
justifyContent="start"
fontSize="10pt"
fontSize="11pt"
color="gray.500"
gap="3px"
alignItems={"center"}
>
{run.status && (
<>
<Text fontWeight={500} color="green.400">
<RunListItemStatus run={run} />
</Text>
<Text></Text>
</>
)}
<RunListItemStatus run={run} />
<Text></Text>
<Text>{relativeTime}</Text>
</Flex>
</Flex>
Expand All @@ -170,6 +183,7 @@ export const RunList = () => {
queryFn: async () => {
return await listRuns();
},
retry: false,
});
const { showRunId, runId } = useRecceActionContext();
const handleSelectRun = (runId: string) => {
Expand Down
4 changes: 2 additions & 2 deletions js/src/components/run/RunResultPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const _LoadableRunView = ({
{run?.check_id ? (
<Button
leftIcon={<CheckIcon />}
isDisabled={!runId || !run?.result}
isDisabled={!runId || !run?.result || !!error}
size="sm"
colorScheme="blue"
onClick={handleGoToCheck}
Expand All @@ -142,7 +142,7 @@ export const _LoadableRunView = ({
) : (
<Button
leftIcon={<CheckIcon />}
isDisabled={!runId || !run?.result}
isDisabled={!runId || !run?.result || !!error}
size="sm"
colorScheme="blue"
onClick={handleAddToChecklist}
Expand Down
2 changes: 1 addition & 1 deletion js/src/lib/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ export interface Run<PT = any, RT = any> {
params?: PT;
result?: RT;
error?: string;
status?: "successful" | "failed" | "cancelled";
status?: "finished" | "failed" | "cancelled" | "running" | string;
}
1 change: 1 addition & 0 deletions js/src/lib/hooks/useRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useRun = (runId?: string): UseRunResult => {
},
enabled: !!runId,
refetchInterval: isPolling ? 50 : false,
retry: false,
});

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions recce/apis/run_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def submit_run(type, params, check_id=None):
if dbt_adaptor.adapter is None:
raise RecceException("Recce Server is not launched under DBT project folder.")

run = Run(type=run_type, params=params, check_id=check_id)
run = Run(type=run_type, params=params, check_id=check_id, status=RunStatus.RUNNING)
run.name = generate_run_name(run)
RunDAO().create(run)

Expand All @@ -132,7 +132,7 @@ async def update_run_result(run_id, result, error):
return
if result is not None:
run.result = result
run.status = RunStatus.SUCCESSFUL
run.status = RunStatus.FINISHED
if error is not None:
run.error = str(error)
if run.status != RunStatus.CANCELLED:
Expand Down
5 changes: 4 additions & 1 deletion recce/models/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ class RunProgress(BaseModel):


class RunStatus(Enum):
SUCCESSFUL = 'successful'
FINISHED = 'finished'
FAILED = 'failed'
CANCELLED = 'cancelled'
RUNNING = 'running'
# This is a special status only in v0.36.0. Replaced by FINISHED. To be removed in the future.
SUCCESSFUL = 'successful'


class Run(BaseModel):
Expand Down

0 comments on commit ce73702

Please sign in to comment.