Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-2002 VICE Countdown Timers #584

Merged
merged 7 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/static/locales/en/analyses.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"terminateAnalysisTitle": "Terminate Analysis",
"terminateAnalysisTitle_plural": "Terminate Analyses",
"terminateBtn": "Terminate",
"timeLimitCountdown": "Time Remaining: {{timeLimitCountdown}}",
"timeLimitError": "Unable to get the current time limit. Please try again.",
"timeLimitExtended": "Time limit for {{analysisName}} has been extended. This analysis will end on {{newTimeLimit}}",
"theirs": "Shared with me",
Expand Down
1 change: 1 addition & 0 deletions public/static/locales/en/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"analysisCompletedOrigination": "<status><bold>{{status}}</bold></status> in {{totalRunTime}} - ({{date}})",
"analysisOrigination": "<status><bold>{{status}}</bold></status> - {{date}}",
"analysisRunningOrigination": "<status><bold>{{status}}</bold></status> for {{runningTime}} ({{date}})",
"analysisRunningTimeLimit": "<status><bold>{{status}}</bold></status> - Time Remaining: {{timeLimitCountdown}}",
"banner": "Banner",
"buy": "Buy",
"by": "By",
Expand Down
4 changes: 2 additions & 2 deletions src/components/analyses/details/InfoPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Updates(props) {
const timestamp = update.timestamp;
const message = update.message;
return (
<>
<React.Fragment key={updateIndex}>
<ListItem id={buildID(baseId, updateIndex)}>
<ListItemText
primary={`${formatDate(timestamp)} - ${status}`}
Expand All @@ -69,7 +69,7 @@ function Updates(props) {
/>
</ListItem>
<Divider component="li" />
</>
</React.Fragment>
);
})}
</List>
Expand Down
6 changes: 5 additions & 1 deletion src/components/analyses/details/ParamsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function AnalysisParams(props) {
let columns = columnData(t);

if (isParamsFetching) {
return <TableLoading numColumns={3} numRows={10} />;
return (
<Table>
<TableLoading numColumns={3} numRows={10} />
</Table>
);
}

if (!parameters && !isParamsFetching && !paramsFetchError) {
Expand Down
53 changes: 23 additions & 30 deletions src/components/analyses/landing/AnalysisSubmissionLanding.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import {
cancelAnalysis,
extendVICEAnalysisTimeLimit,
getAnalysis,
getTimeLimitForVICEAnalysis,
renameAnalysis,
updateAnalysisComment,
useAnalysisInfo,
useAnalysisParameters,
VICE_TIME_LIMIT_QUERY_KEY,
} from "serviceFacades/analyses";
import { getAnalysisShareWithSupportRequest } from "serviceFacades/sharing";
import {
Expand All @@ -29,6 +27,7 @@ import DetailsPanel from "../details/DetailsPanel";
import InfoPanel from "../details/InfoPanel";
import ParamsPanel from "../details/ParamsPanel";
import AnalysisStatusIcon from "../AnalysisStatusIcon";
import useAnalysisTimeLimitCountdown from "../useAnalysisTimeLimitCountdown";

import ShareWithSupportDialog from "components/analyses/ShareWithSupportDialog";
import TerminateAnalysisDialog from "components/analyses/TerminateAnalysisDialog";
Expand Down Expand Up @@ -104,16 +103,19 @@ export default function AnalysisSubmissionLanding(props) {

const [confirmExtendTimeLimitDlgOpen, setConfirmExtendTimeLimitDlgOpen] =
React.useState(false);
const [timeLimitQueryEnabled, setTimeLimitQueryEnabled] =
React.useState(false);
const [timeLimit, setTimeLimit] = React.useState();
const [pendingTerminationDlgOpen, setPendingTerminationDlgOpen] =
React.useState(false);

const { timeLimit, timeLimitCountdown } = useAnalysisTimeLimitCountdown(
analysis,
showErrorAnnouncer
);

const username = getAnalysisUser(analysis, config);
const isBatch = isBatchAnalysis(analysis);
const isVICE = isInteractive(analysis);
const allowTimeExtn = allowAnalysisTimeExtn(analysis, username, config);
const allowTimeExtn =
timeLimit && allowAnalysisTimeExtn(analysis, username, config);
const allowCancel = allowAnalysesCancel([analysis], username, config);
const allowRelaunch = allowAnalysesRelaunch([analysis]);
const allowEdit = allowAnalysisEdit(analysis, username, config);
Expand Down Expand Up @@ -187,22 +189,6 @@ export default function AnalysisSubmissionLanding(props) {
onSuccess: setParameters,
});

const { isFetching: isFetchingTimeLimit } = useQuery({
queryKey: [VICE_TIME_LIMIT_QUERY_KEY, id],
queryFn: () => getTimeLimitForVICEAnalysis(id),
enabled: timeLimitQueryEnabled,
onSuccess: (resp) => {
//convert the response from seconds to milliseconds
setTimeLimit({
[id]: formatDate(resp?.time_limit * 1000),
});
setConfirmExtendTimeLimitDlgOpen(true);
},
onError: (error) => {
showErrorAnnouncer(t("timeLimitError"), error);
},
});

const { mutate: shareAnalysesMutation, isLoading: shareLoading } =
useMutation(submitAnalysisSupportRequest, {
onSuccess: (responses) => {
Expand Down Expand Up @@ -277,7 +263,6 @@ export default function AnalysisSubmissionLanding(props) {
useMutation(extendVICEAnalysisTimeLimit, {
onSuccess: (resp) => {
setConfirmExtendTimeLimitDlgOpen(false);
setTimeLimit(null);
//convert the response from seconds to milliseconds
announce({
text: t("timeLimitExtended", {
Expand All @@ -304,11 +289,7 @@ export default function AnalysisSubmissionLanding(props) {
});
};

const busy =
isFetching ||
analysisLoading ||
isFetchingTimeLimit ||
extensionLoading;
const busy = isFetching || analysisLoading || extensionLoading;

if (busy) {
return <GridLoading rows={25} baseId={baseId} />;
Expand Down Expand Up @@ -354,6 +335,16 @@ export default function AnalysisSubmissionLanding(props) {
analysis={analysis}
date={formatDate(analysis?.startdate)}
/>
{timeLimitCountdown && (
<Typography
color="primary"
variant="subtitle2"
>
{t("timeLimitCountdown", {
timeLimitCountdown,
})}
</Typography>
)}
</Grid>
</Grid>
</Grid>
Expand Down Expand Up @@ -461,7 +452,9 @@ export default function AnalysisSubmissionLanding(props) {
}
handleRefresh={refreshAnalysis}
handleTimeLimitExtnClick={() => {
setTimeLimitQueryEnabled(true);
setConfirmExtendTimeLimitDlgOpen(
true
);
}}
handleShareWithSupport={() =>
setHelpOpen(true)
Expand Down Expand Up @@ -593,7 +586,7 @@ export default function AnalysisSubmissionLanding(props) {
confirmButtonText={t("extend")}
title={t("extendTime")}
contentText={t("extendTimeLimitMessage", {
timeLimit: timeLimit ? timeLimit[id] : "",
timeLimit: formatDate(timeLimit),
})}
/>
</PageWrapper>
Expand Down
11 changes: 2 additions & 9 deletions src/components/analyses/listing/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ import ids from "../ids";
import buildID from "components/utils/DebugIDUtil";

import {
allowAnalysesCancel,
allowAnalysisTimeExtn,
isBatchAnalysis,
isInteractive,
isTerminated,
useGotoOutputFolderLink,
useRelaunchLink,
} from "../utils";

import { useConfig } from "contexts/config";

import { Grid, IconButton } from "@mui/material";
import {
Cancel as CancelIcon,
Expand Down Expand Up @@ -92,26 +88,23 @@ export default function Actions(props) {
const {
analysis,
allowBatchDrillDown = true,
allowCancel,
allowTimeExtn,
handleDetailsClick,
handleInteractiveUrlClick,
handleTerminateSelected,
handleBatchIconClick,
setPendingTerminationDlgOpen,
baseId,
username,
handleTimeLimitExtnClick,
setVICELogsDlgOpen,
} = props;

const [config] = useConfig();

const interactiveUrls = analysis.interactive_urls;
const isDisabled = analysis.app_disabled;

const isBatch = isBatchAnalysis(analysis);
const isVICE = isInteractive(analysis);
const allowCancel = allowAnalysesCancel([analysis], username, config);
const allowTimeExtn = allowAnalysisTimeExtn(analysis, username, config);
const [relaunchHref, relaunchAs] = useRelaunchLink(analysis);
const [outputFolderHref, outputFolderAs] = useGotoOutputFolderLink(
analysis?.resultfolderid
Expand Down
52 changes: 11 additions & 41 deletions src/components/analyses/listing/Listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import ViceLogsViewer from "components/analyses/ViceLogsViewer";

import {
ANALYSES_LISTING_QUERY_KEY,
VICE_TIME_LIMIT_QUERY_KEY,
cancelAnalyses,
deleteAnalyses,
getAnalyses,
relaunchAnalyses,
renameAnalysis,
updateAnalysisComment,
extendVICEAnalysisTimeLimit,
getTimeLimitForVICEAnalysis,
} from "serviceFacades/analyses";

import { useBagAddItems } from "serviceFacades/bags";
Expand Down Expand Up @@ -131,29 +129,13 @@ function Listing(props) {
useState(false);
const [terminateAnalysisDlgOpen, setTerminateAnalysisDlgOpen] =
useState(false);
const [timeLimitQueryEnabled, setTimeLimitQueryEnabled] = useState(false);
const [timeLimit, setTimeLimit] = useState();

const handleTerminateSelected = () => setTerminateAnalysisDlgOpen(true);

// Get QueryClient from the context
const queryClient = useQueryClient();

/**
* There is a small gap between when the user click on the Extend button / menu item
* and the time loading mask appears because the getTimeLimitForVICEAnalysis query is
* controlled by timeLimitQueryEnabled state. So the user has a chance to click
* on the same button again or choose to extend time limit on another analysis or
* even do something else. To avoid potential race condition,
* I am storing / checking the selected analysis id for which the timestamp is fetched.
* This should also help in debugging if the race condition still happens.
*/
useEffect(() => {
if (timeLimit && selected?.length > 0 && timeLimit[selected[0]]) {
setConfirmExtendTimeLimitDlgOpen(true);
}
}, [timeLimit, selected]);

const { isFetching, error } = useQuery({
queryKey: analysesKey,
queryFn: () => getAnalyses(analysesKey[1]),
Expand Down Expand Up @@ -280,30 +262,16 @@ function Listing(props) {
},
});

const { isFetching: isFetchingTimeLimit } = useQuery({
queryKey: [VICE_TIME_LIMIT_QUERY_KEY, selected[0]],
queryFn: () => getTimeLimitForVICEAnalysis(selected[0]),
enabled: timeLimitQueryEnabled,
onSuccess: (resp) => {
//convert the response from seconds to milliseconds
setTimeLimit({
[selected[0]]: formatDate(resp?.time_limit * 1000),
});
},
onError: (error) => {
showErrorAnnouncer(t("timeLimitError"), error);
},
});

const { mutate: doTimeLimitExtension, isLoading: extensionLoading } =
useMutation(extendVICEAnalysisTimeLimit, {
onSuccess: (resp) => {
setConfirmExtendTimeLimitDlgOpen(false);
setTimeLimit(null);
const newTimeLimit = resp?.time_limit * 1000;
setTimeLimit(newTimeLimit || null);
//convert the response from seconds to milliseconds
announce({
text: t("timeLimitExtended", {
newTimeLimit: formatDate(resp?.time_limit * 1000),
newTimeLimit: formatDate(newTimeLimit),
analysisName: getSelectedAnalyses()[0]?.name,
}),
variant: SUCCESS,
Expand Down Expand Up @@ -713,15 +681,13 @@ function Listing(props) {
cancelLoading,
deleteLoading,
relaunchLoading,
isFetchingTimeLimit,
extensionLoading,
]);

return (
<>
<AnalysesToolbar
baseId={baseId}
selected={selected}
username={userProfile?.id}
getSelectedAnalyses={getSelectedAnalyses}
handleAppTypeFilterChange={handleAppTypeFilterChange}
Expand All @@ -744,7 +710,10 @@ function Listing(props) {
handleBatchIconClick={handleBatchIconClick}
canShare={sharingEnabled}
setPendingTerminationDlgOpen={setPendingTerminationDlgOpen}
handleTimeLimitExtnClick={() => setTimeLimitQueryEnabled(true)}
handleTimeLimitExtnClick={(timeLimit) => {
setTimeLimit(timeLimit);
setConfirmExtendTimeLimitDlgOpen(true);
}}
onRefreshSelected={onRefreshSelected}
setVICELogsDlgOpen={setVICELogsDlgOpen}
/>
Expand All @@ -767,8 +736,9 @@ function Listing(props) {
handleDetailsClick={onDetailsSelected}
handleStatusClick={handleStatusClick}
setPendingTerminationDlgOpen={setPendingTerminationDlgOpen}
handleTimeLimitExtnClick={() => {
setTimeLimitQueryEnabled(true);
handleTimeLimitExtnClick={(timeLimit) => {
setTimeLimit(timeLimit);
setConfirmExtendTimeLimitDlgOpen(true);
}}
setVICELogsDlgOpen={setVICELogsDlgOpen}
/>
Expand Down Expand Up @@ -865,7 +835,7 @@ function Listing(props) {
confirmButtonText={t("extend")}
title={t("extendTime")}
contentText={t("extendTimeLimitMessage", {
timeLimit: timeLimit ? timeLimit[selected[0]] : "",
timeLimit: formatDate(timeLimit),
})}
/>
<ViceLogsViewer
Expand Down
Loading
Loading