Skip to content
Snippets Groups Projects
Commit e656ebd8 authored by Alexander Madsen's avatar Alexander Madsen
Browse files

Merge branch 'CE-2072-convert-useJobLogById' into 'develop'

CE-2072: convert useJobLogById

See merge request !361
parents e9b908c6 9a3ebde1
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!361CE-2072: convert useJobLogById
Pipeline #160450 passed
......@@ -272,14 +272,6 @@ export function useJobById() {
return useAsync({ fcn: method, call: false, init: null });
}
export function useJobLogById() {
const api = useContext(apiContext);
const method = useCallAndUnpack((awxJobId) =>
api.apis.Deployments.fetchDeploymentJobLog({ awx_job_id: awxJobId })
);
return useAsync({ fcn: method, call: false, init: null });
}
export function useUpdateAndDeployIoc(id, onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
......
import React, { useCallback, useRef, useEffect } from "react";
import React, {
useCallback,
useRef,
useEffect,
useContext,
useMemo
} from "react";
import { LinearProgress, Typography, Container, Stack } from "@mui/material";
import { useJobLogById } from "../../api/SwaggerApi";
import { Console } from "../common/Console/Console";
import { useSafePolling } from "../../hooks/Polling";
import { apiContext } from "../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
const LOG_POLL_INTERVAL = 5000;
export function DeploymentJobOutput({ deploymentJob }) {
const [log, getLogById /* reset*/, , logLoading] = useJobLogById();
const client = useContext(apiContext);
const params = useMemo(
() => ({
awx_job_id: deploymentJob?.id
}),
[deploymentJob]
);
const {
value: log,
wrapper: getLogById,
loading: logLoading,
dataReady: logDataReady
} = useAPIMethod({
fcn: client.apis.Deployments.fetchDeploymentJobLog,
params
});
const finalResultsNeeded = useRef(true);
useEffect(() => {
......@@ -19,7 +44,7 @@ export function DeploymentJobOutput({ deploymentJob }) {
finalResultsNeeded.current = !deploymentJob.finished;
}
}, [deploymentJob.finished, deploymentJob.id, getLogById]);
useSafePolling(getLog, logLoading, LOG_POLL_INTERVAL);
useSafePolling(getLog, logLoading || !logDataReady, LOG_POLL_INTERVAL);
const dataReady = useCallback(() => {
return deploymentJob?.started;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment