Skip to content

Commit

Permalink
🪟🐛 Keep refetching debug infos while job is running (#14341)
Browse files Browse the repository at this point in the history
* Keep refetching debug infos while job is running

* Set delay to 2 minutes
  • Loading branch information
timroes authored Jul 12, 2022
1 parent bfa54ac commit 0c80644
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const JobLogs: React.FC<JobLogsProps> = ({ jobIsFailed, job }) => {

const id: number | string = (job as JobsWithJobs).job?.id ?? (job as SynchronousJobReadWithStatus).id;

const debugInfo = useGetDebugInfoJob(id, typeof id === "number");
const debugInfo = useGetDebugInfoJob(id, typeof id === "number", true);

const { hash } = useLocation();
const [attemptNumber, setAttemptNumber] = useState<number>(() => {
Expand Down
18 changes: 16 additions & 2 deletions airbyte-webapp/src/services/job/JobService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ export const useGetJob = (id: number, enabled = true) => {
});
};

export const useGetDebugInfoJob = (id: number, enabled = true): JobDebugInfoRead | undefined => {
export const useGetDebugInfoJob = (
id: number,
enabled = true,
refetchWhileRunning = false
): JobDebugInfoRead | undefined => {
const service = useGetJobService();

return useSuspenseQuery(jobsKeys.getDebugInfo(id), () => service.getDebugInfo(id), {
refetchInterval: false,
refetchInterval: !refetchWhileRunning
? false
: (data) => {
// If refetchWhileRunning was true, we keep refetching debug info (including logs), while the job is still
// running or hasn't ended too long ago. We need some time after the last attempt has stopped, since logs
// keep incoming for some time after the job has already been marked as finished.
const lastAttemptEndTimestamp = data?.attempts[data.attempts.length - 1].attempt.endedAt;
// While no attempt ended timestamp exists yet (i.e. the job is still running) or it hasn't ended
// more than 2 minutes (2 * 60 * 1000ms) ago, keep refetching
return lastAttemptEndTimestamp && Date.now() - lastAttemptEndTimestamp * 1000 > 2 * 60 * 1000 ? false : 2500;
},
enabled,
});
};
Expand Down

0 comments on commit 0c80644

Please sign in to comment.