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

Fixed: Re-newed import/export request failed immediately if the previous failed #8649

Merged
merged 7 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions changelog.d/20241106_095739_sekachev.bs_fixed_exception_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Fixed issue 'Cannot read properties of undefined (reading 'push')'
(<https://github.com/cvat-ai/cvat/pull/8648>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/XXXX>)
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 6, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update the PR link in the changelog entry.

The changelog entry follows the correct format and provides a clear description of the fix. However, the PR link needs to be updated.

Apply this diff to fix the PR link:

- (<https://github.com/cvat-ai/cvat/pull/XXXX>)
+ (<https://github.com/cvat-ai/cvat/pull/8649>)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Fixed
- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/XXXX>)
### Fixed
- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/8649>)

Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update link

Copy link
Contributor

Choose a reason for hiding this comment

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

@klakhov Yes, please update the link in the changelog entry to point to the correct PR. Replace XXXX with 8649 in the link. Here is the updated entry:

### Fixed

- Re-newed import/export request failed immediately if the previous failed
  (<https://github.com/cvat-ai/cvat/pull/8649>)

33 changes: 18 additions & 15 deletions cvat-core/src/requests-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RequestsManager {
requestDelayIdx: number | null,
request: Request | null,
timeout: number | null;
promise?: Promise<Request>;
promise: Promise<Request>;
}>;

private requestStack: number[];
Expand Down Expand Up @@ -71,6 +71,7 @@ class RequestsManager {
}
return this.listening[requestID].promise;
}

const promise = new Promise<Request>((resolve, reject) => {
const timeoutCallback = async (): Promise<void> => {
// We make sure that no more than REQUESTS_COUNT requests are sent simultaneously
Expand Down Expand Up @@ -131,27 +132,29 @@ class RequestsManager {
message: `Could not get a status of the request ${requestID}. ${error.toString()}`,
})));
}

delete this.listening[requestID];
reject(error);
}
}
};

if (initialRequest?.status === RQStatus.FAILED) {
reject(new RequestError(initialRequest?.message));
} else {
this.listening[requestID] = {
onUpdate: callback ? [callback] : [],
timeout: window.setTimeout(timeoutCallback),
request: initialRequest,
requestDelayIdx: 0,
};
}
Promise.resolve().then(() => {
// running as microtask to make sure "promise" was initialized
if (initialRequest?.status === RQStatus.FAILED) {
reject(new RequestError(initialRequest?.message));
} else {
this.listening[requestID] = {
onUpdate: callback ? [callback] : [],
timeout: window.setTimeout(timeoutCallback),
request: initialRequest,
requestDelayIdx: 0,
promise,
};
}
});
});

this.listening[requestID] = {
...this.listening[requestID],
promise,
};
return promise;
}

Expand Down
134 changes: 75 additions & 59 deletions cvat-ui/src/actions/export-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
// SPDX-License-Identifier: MIT

import { ActionUnion, createAction, ThunkAction } from 'utils/redux';

import { Storage, ProjectOrTaskOrJob, Job } from 'cvat-core-wrapper';
import {
getInstanceType, RequestInstanceType, listen, RequestsActions,
shouldListenForProgress,
Storage, ProjectOrTaskOrJob, Job, getCore, StorageLocation,
} from 'cvat-core-wrapper';
import {
getInstanceType, RequestInstanceType, listen,
RequestsActions, updateRequestProgress,
} from './requests-actions';

export enum ExportActionTypes {
Expand All @@ -24,6 +25,8 @@ export enum ExportActionTypes {
EXPORT_BACKUP_FAILED = 'EXPORT_BACKUP_FAILED',
}

const core = getCore();

export const exportActions = {
openExportDatasetModal: (instance: ProjectOrTaskOrJob) => (
createAction(ExportActionTypes.OPEN_EXPORT_DATASET_MODAL, { instance })
Expand Down Expand Up @@ -75,52 +78,33 @@ export const exportActions = {
),
};

export async function listenExportDatasetAsync(
rqID: string,
dispatch: (action: ExportActions | RequestsActions) => void,
params: {
instance: ProjectOrTaskOrJob | RequestInstanceType,
format: string,
saveImages: boolean,
},
): Promise<void> {
const { instance, format, saveImages } = params;
const resource = saveImages ? 'dataset' : 'annotations';

const instanceType = getInstanceType(instance);
try {
const result = await listen(rqID, dispatch);
const target = !result?.url ? 'cloudstorage' : 'local';
dispatch(exportActions.exportDatasetSuccess(
instance, instanceType, format, resource, target,
));
} catch (error) {
dispatch(exportActions.exportDatasetFailed(instance, instanceType, format, resource, error));
}
}

/** *
* Function is supposed to be used when a new dataset export request initiated by a user
** */
export const exportDatasetAsync = (
instance: ProjectOrTaskOrJob,
format: string,
saveImages: boolean,
useDefaultSettings: boolean,
targetStorage: Storage,
name?: string,
): ThunkAction => async (dispatch, getState) => {
const state = getState();

): ThunkAction => async (dispatch) => {
const resource = saveImages ? 'dataset' : 'annotations';
const instanceType = getInstanceType(instance);

try {
const rqID = await instance.annotations
.exportDataset(format, saveImages, useDefaultSettings, targetStorage, name);
if (shouldListenForProgress(rqID, state.requests)) {
await listenExportDatasetAsync(rqID, dispatch, {
instance, format, saveImages,

if (rqID) {
await core.requests.listen(rqID, {
callback: (updatedRequest) => updateRequestProgress(updatedRequest, dispatch),
});
}
if (!rqID) {
const target = targetStorage.location === StorageLocation.LOCAL ? 'local' : 'cloudstorage';
dispatch(exportActions.exportDatasetSuccess(
instance, instanceType, format, resource, target,
));
} else {
dispatch(exportActions.exportDatasetSuccess(
instance, instanceType, format, resource,
));
Expand All @@ -130,47 +114,79 @@ export const exportDatasetAsync = (
}
};

export async function listenExportBackupAsync(
/** *
* Function is supposed to be used when a new backup export request initiated by a user
** */
export const exportBackupAsync = (
instance: Exclude<ProjectOrTaskOrJob, Job>,
targetStorage: Storage,
useDefaultSetting: boolean,
fileName: string,
): ThunkAction => async (dispatch) => {
const instanceType = getInstanceType(instance) as 'project' | 'task';
try {
const rqID = await instance.backup(targetStorage, useDefaultSetting, fileName);
if (rqID) {
await core.requests.listen(rqID, {
callback: (updatedRequest) => updateRequestProgress(updatedRequest, dispatch),
});
const target = targetStorage.location === StorageLocation.LOCAL ? 'local' : 'cloudstorage';
dispatch(exportActions.exportBackupSuccess(instance, instanceType, target));
} else {
dispatch(exportActions.exportBackupSuccess(instance, instanceType));
}
} catch (error) {
dispatch(exportActions.exportBackupFailed(instance, instanceType, error as Error));
}
};

/** *
* Function is supposed to be used when application starts listening to existing dataset export request
** */
export async function listenExportDatasetAsync(
rqID: string,
dispatch: (action: ExportActions | RequestsActions) => void,
params: {
instance: Exclude<ProjectOrTaskOrJob, Job> | RequestInstanceType,
instance: ProjectOrTaskOrJob | RequestInstanceType,
format: string,
saveImages: boolean,
},
): Promise<void> {
const { instance } = params;
const instanceType = getInstanceType(instance) as 'project' | 'task';
const { instance, format, saveImages } = params;
const resource = saveImages ? 'dataset' : 'annotations';

const instanceType = getInstanceType(instance);
try {
const result = await listen(rqID, dispatch);
const target = !result?.url ? 'cloudstorage' : 'local';
dispatch(exportActions.exportBackupSuccess(instance, instanceType, target));
dispatch(exportActions.exportDatasetSuccess(
instance, instanceType, format, resource, target,
));
} catch (error) {
dispatch(exportActions.exportBackupFailed(instance, instanceType, error as Error));
dispatch(exportActions.exportDatasetFailed(instance, instanceType, format, resource, error));
}
}

export const exportBackupAsync = (
instance: Exclude<ProjectOrTaskOrJob, Job>,
targetStorage: Storage,
useDefaultSetting: boolean,
fileName: string,
): ThunkAction => async (dispatch, getState) => {
const state = getState();

/** *
* Function is supposed to be used when application starts listening to existing backup export request
** */
export async function listenExportBackupAsync(
rqID: string,
dispatch: (action: ExportActions | RequestsActions) => void,
params: {
instance: Exclude<ProjectOrTaskOrJob, Job> | RequestInstanceType,
},
): Promise<void> {
const { instance } = params;
const instanceType = getInstanceType(instance) as 'project' | 'task';

try {
const rqID = await instance
.backup(targetStorage, useDefaultSetting, fileName);
if (shouldListenForProgress(rqID, state.requests)) {
await listenExportBackupAsync(rqID, dispatch, { instance });
}
if (!rqID) {
dispatch(exportActions.exportBackupSuccess(instance, instanceType));
}
const result = await listen(rqID, dispatch);
const target = !result?.url ? 'cloudstorage' : 'local';
dispatch(exportActions.exportBackupSuccess(instance, instanceType, target));
} catch (error) {
dispatch(exportActions.exportBackupFailed(instance, instanceType, error as Error));
}
};
}

export type ExportActions = ActionUnion<typeof exportActions>;
Loading
Loading