diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index 59444ee7b8d0761413d3c91d724a71ee448b54de..e55138b587184a61be397929c3b0765bc5f68e4e 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -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( diff --git a/src/components/deployments/DeploymentJobOutput.js b/src/components/deployments/DeploymentJobOutput.js index 3d93d15060bb7b27fa2b12beec959a6e8fae3726..6356477ede2ac9de95bbeb4a3c547d70a2ce7784 100644 --- a/src/components/deployments/DeploymentJobOutput.js +++ b/src/components/deployments/DeploymentJobOutput.js @@ -1,12 +1,37 @@ -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;