Skip to content

Commit

Permalink
Optional chaining doesnt work, so instead make the abort controller n…
Browse files Browse the repository at this point in the history
…on-optional

Signed-off-by: cosa65 <[email protected]>
  • Loading branch information
cosa65 committed Nov 30, 2023
1 parent ab401e1 commit 67dab90
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const AddMetadataButton = ({ samplesTableRef }) => {
}

try {
await prepareAndUploadFileToS3(file, uploadUrlParams, 'cellLevelMeta', onUpdateUploadStatus);
await prepareAndUploadFileToS3(file, uploadUrlParams, 'cellLevelMeta', new AbortController(), onUpdateUploadStatus);
} catch (e) {
pushNotificationMessage('error', 'Something went wrong while uploading your metadata file.');
console.log(e);
Expand Down
10 changes: 6 additions & 4 deletions src/utils/upload/processMultipartUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ const FILE_CHUNK_SIZE = 10000000;
const MAX_RETRIES = 2;

const putPartInS3 = async (
blob, signedUrl, onUploadProgress, currentRetry = 0, abortController = null,
blob, signedUrl, onUploadProgress, abortController, currentRetry = 0,
) => {
try {
return await axios.request({
method: 'put',
data: blob,
url: signedUrl,
signal: abortController?.signal,
signal: abortController.signal,
headers: {
'Content-Type': 'application/octet-stream',
},
onUploadProgress,
});
} catch (e) {
if (currentRetry < MAX_RETRIES) {
return await putPartInS3(blob, signedUrl, onUploadProgress, currentRetry + 1);
return await putPartInS3(
blob, signedUrl, onUploadProgress, abortController, currentRetry + 1,
);
}

throw e;
Expand All @@ -42,8 +44,8 @@ const processMultipartUpload = async (
blob,
signedUrl,
createOnUploadProgressForPart(index),
0,
abortController,
0,
);

promises.push(req);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/upload/processUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import endUserMessages from 'utils/endUserMessages';
import pushNotificationMessage from 'utils/pushNotificationMessage';

const prepareAndUploadFileToS3 = async (
file, uploadUrlParams, type, onStatusUpdate = () => { }, abortController = null,
file, uploadUrlParams, type, abortController, onStatusUpdate = () => { },
) => {
let parts = null;
const { signedUrls, uploadId, fileId } = uploadUrlParams;
Expand Down Expand Up @@ -121,7 +121,7 @@ const createAndUploadSampleFile = async (file, experimentId, sampleId, dispatch,
);

const uploadUrlParams = { signedUrls, uploadId, fileId: sampleFileId };
await prepareAndUploadFileToS3(file, uploadUrlParams, 'sample', updateSampleFileUploadProgress, abortController);
await prepareAndUploadFileToS3(file, uploadUrlParams, 'sample', abortController, updateSampleFileUploadProgress);
} catch (e) {
dispatch(updateSampleFileUpload(
experimentId, sampleId, sampleFileId, fileType, UploadStatus.UPLOAD_ERROR,
Expand Down

0 comments on commit 67dab90

Please sign in to comment.