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

🪟🐛 Keep refetching debug infos while job is running #14341

Merged
merged 5 commits into from
Jul 12, 2022
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says 6 minutes, but this looks like 2. Is one of them incorrect?

Copy link
Collaborator Author

@timroes timroes Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot to update that :) I created this originally with 6 minutes, but Davin clarified for me, that the log is supposed to be max 1 minute late based on how our log fetching implementation worked, so I felt 2 minutes might be a long enough grace period to make sure. Updated the PR description now as well.

},
enabled,
});
};
Expand Down