Skip to content

Commit

Permalink
feat(cli): show progress during document upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sperka committed Nov 8, 2023
1 parent 0c58c5d commit 550f078
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/galileo-cli/src/commands/document/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default class DocumentUploadCommand extends Command {
}
}

context.ui.newSpinner().start('Uploading documents');
await accountUtils.uploadDocuments({
documentMetadata: documentMetadata!,
metadataFilepath: metadataFile,
Expand All @@ -119,6 +120,7 @@ export default class DocumentUploadCommand extends Command {
uploadBucket,
uploadKeyPrefix,
});
context.ui.spinner.succeed();

context.ui.newSpinner().start('Loading step functions');
const stepFunctions = await accountUtils.listStepfunctions({
Expand Down
12 changes: 4 additions & 8 deletions packages/galileo-cli/src/lib/account-utils/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export namespace s3 {
} catch (err: any) {
// bucket in another region -- we can ignore it since `region` parameter
// represents our application.
if (err instanceof S3ServiceException && err.name === 'PermanentRedirect') {
if (err instanceof S3ServiceException && (err.name === 'PermanentRedirect' || err.name === 'NoSuchTagSet')) {
// `PermanentRedirect` happens when bucket is in a different region
// we expect this -> noop
// NoSuchTagSet happens when no tags are present for the bucket
// we expect this -> noop, skip
} else {
// anything else --> log it
console.log(`Error: ${JSON.stringify(err, null, 2)}`);
Expand Down Expand Up @@ -139,15 +141,9 @@ export namespace s3 {
partSize: 1024 * 1024 * 5, // optional size of each part, in bytes, at least 5MB
leavePartsOnError: false, // optional manually handle dropped parts
});
upload.on('httpUploadProgress', (progress) => {
context.ui.spinner.text = `\t[${i + 1}/${docKeys.length}] ${progress.Key}: ${progress.part}/${progress.total}`;
});

context.ui.spinner.text = `Uploading ${options.uploadBucket}/${options.uploadKeyPrefix}/${docKey}`;

await upload.done();
context.ui.spinner.text = `\t[${i + 1}/${docKeys.length}] ${docKey}`;
context.ui.spinner.text = `Uploading documents ${i + 1}/${docKeys.length}`;
}
context.ui.spinner.succeed(`${docKeys.length} documents uploaded`);
};
}

0 comments on commit 550f078

Please sign in to comment.