Skip to content

Commit

Permalink
fix: load error messages for batch jobs when they fail
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Jun 27, 2024
1 parent 1a06645 commit dd88764
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion webapp/src/hooks/ProjectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ export const [ProjectContext, useProjectActions, useProjectContext] =

const changeHandler = ({ data }: BatchJobProgress) => {
const exists = batchOperations?.find((job) => job.id === data.jobId);
let shouldRefetch = false;
if (!exists) {
if (!knownJobs.includes(data.jobId)) {
shouldRefetch = true;
// only refetch jobs first time we see unknown job
setKnownJobs((jobs) => [...jobs, data.jobId]);
setBatchOperations((jobs) => [
Expand All @@ -92,12 +94,15 @@ export const [ProjectContext, useProjectActions, useProjectContext] =
errorMessage: data.errorMessage,
},
]);
batchJobsLoadable.refetch();
}
} else {
setBatchOperations((jobs) =>
jobs?.map((job) => {
if (job.id === data.jobId) {
if (data.status === 'FAILED' && data.status !== job.status) {
// load error message
shouldRefetch = true;
}
return {
...job,
totalItems: data.total ?? job.totalItems,
Expand All @@ -110,6 +115,9 @@ export const [ProjectContext, useProjectActions, useProjectContext] =
})
);
}
if (shouldRefetch) {
batchJobsLoadable.refetch({ fetching: true });
}
};

const changeHandlerRef = useRef(changeHandler);
Expand Down

0 comments on commit dd88764

Please sign in to comment.