Skip to content

Commit

Permalink
only notify for jobs in this workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
calypsomatic committed Jan 14, 2025
1 parent 65ebd8e commit 57f5299
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/workspace-data/import-jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ describe('useImportJobs', () => {
it('notifies if a failed job is in import store', async () => {
// Arrange
asyncImportJobStore.set([
{ targetWorkspace: { namespace: 'test-workspaces', name: 'google-workspace' }, jobId: 'job-1' },
{ targetWorkspace: { namespace: 'test-workspaces', name: 'google-workspace2' }, jobId: 'job-4' },
{ targetWorkspace: { namespace: 'test-workspaces', name: 'google-workspace' }, jobId: 'job-2' },
]);

const listImportJobs: MockedFn<WorkspaceContract['listImportJobs']> = jest.fn();
listImportJobs.mockResolvedValue([{ jobId: 'job-1' }, { jobId: 'job-3' }]);
const getImportJobStatus: MockedFn<WorkspaceContract['getImportJobStatus']> = jest.fn();
getImportJobStatus.mockResolvedValue({ jobId: 'job-1', status: 'Error', message: 'This job failed.' });
getImportJobStatus.mockResolvedValue({ jobId: 'job-2', status: 'Error', message: 'This job failed.' });

asMockedFn(Workspaces).mockReturnValue(
partial<WorkspacesAjaxContract>({
Expand All @@ -100,6 +100,8 @@ describe('useImportJobs', () => {
await act(() => hookReturnRef.current.refresh());

// Assert
expect(getImportJobStatus).toHaveBeenCalledWith('job-2');
expect(getImportJobStatus).not.toHaveBeenCalledWith('job-4');
expect(notify).toHaveBeenCalledWith('error', 'Error importing data.', {
message: 'This job failed.',
});
Expand Down
5 changes: 4 additions & 1 deletion src/workspace-data/import-jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export const useImportJobs = (workspace: WorkspaceWrapper): UseImportJobsResult
// In cases where jobs failed before this query completes, users won't be notified of failure
// But they are momentarily in the job store, so check for them and notify here
const jobsToNotify = allRunningJobs.filter(
(job) => !runningJobsInWorkspace.some(({ jobId }) => job.jobId === jobId)
(job) =>
job.targetWorkspace.namespace === namespace &&
job.targetWorkspace.name === name &&
!runningJobsInWorkspace.some(({ jobId }) => job.jobId === jobId)
);

jobsToNotify.forEach((job) => {
Expand Down

0 comments on commit 57f5299

Please sign in to comment.