-
Notifications
You must be signed in to change notification settings - Fork 218
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
Feat/158222 158279 bulk export for file upload types other than s3/gcs #9467
Merged
yuki-takei
merged 6 commits into
feat/page-bulk-export
from
feat/158222-158279-bulk-export-to-normal-fs
Dec 11, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d2509d7
enable page bulk export for all file upload types
arafubeatbox 85ea3e6
Merge branch 'feat/page-bulk-export' into feat/158222-158279-bulk-exp…
arafubeatbox b9c2f3d
Merge branch 'feat/page-bulk-export' into feat/158222-158279-bulk-exp…
arafubeatbox 8b0b790
enable bulk export for file upload types other than s3/gcs
arafubeatbox e38080f
remove job stream when job completes
arafubeatbox a6a9607
modify gcs uploadAttachment to use stream
arafubeatbox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 0 additions & 117 deletions
117
...e-bulk-export/server/service/page-bulk-export-job-cron/steps/compress-and-upload-async.ts
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...es/page-bulk-export/server/service/page-bulk-export-job-cron/steps/compress-and-upload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { Archiver } from 'archiver'; | ||
import archiver from 'archiver'; | ||
|
||
import { PageBulkExportJobStatus } from '~/features/page-bulk-export/interfaces/page-bulk-export'; | ||
import { SupportedAction } from '~/interfaces/activity'; | ||
import { AttachmentType } from '~/server/interfaces/attachment'; | ||
import type { IAttachmentDocument } from '~/server/models/attachment'; | ||
import { Attachment } from '~/server/models/attachment'; | ||
import type { FileUploader } from '~/server/service/file-uploader'; | ||
import loggerFactory from '~/utils/logger'; | ||
|
||
import type { IPageBulkExportJobCronService } from '..'; | ||
import type { PageBulkExportJobDocument } from '../../../models/page-bulk-export-job'; | ||
|
||
const logger = loggerFactory('growi:service:page-bulk-export-job-cron:compress-and-upload-async'); | ||
|
||
function setUpPageArchiver(): Archiver { | ||
const pageArchiver = archiver('tar', { | ||
gzip: true, | ||
}); | ||
|
||
// good practice to catch warnings (ie stat failures and other non-blocking errors) | ||
pageArchiver.on('warning', (err) => { | ||
if (err.code === 'ENOENT') logger.error(err); | ||
else throw err; | ||
}); | ||
|
||
return pageArchiver; | ||
} | ||
|
||
async function postProcess( | ||
this: IPageBulkExportJobCronService, pageBulkExportJob: PageBulkExportJobDocument, attachment: IAttachmentDocument, fileSize: number, | ||
): Promise<void> { | ||
attachment.fileSize = fileSize; | ||
await attachment.save(); | ||
|
||
pageBulkExportJob.completedAt = new Date(); | ||
pageBulkExportJob.attachment = attachment._id; | ||
pageBulkExportJob.status = PageBulkExportJobStatus.completed; | ||
await pageBulkExportJob.save(); | ||
|
||
this.removeStreamInExecution(pageBulkExportJob._id); | ||
await this.notifyExportResultAndCleanUp(SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED, pageBulkExportJob); | ||
} | ||
|
||
/** | ||
* Execute a pipeline that reads the page files from the temporal fs directory, compresses them, and uploads to the cloud storage | ||
*/ | ||
export async function compressAndUpload(this: IPageBulkExportJobCronService, user, pageBulkExportJob: PageBulkExportJobDocument): Promise<void> { | ||
const pageArchiver = setUpPageArchiver(); | ||
|
||
if (pageBulkExportJob.revisionListHash == null) throw new Error('revisionListHash is not set'); | ||
const originalName = `${pageBulkExportJob.revisionListHash}.${this.compressExtension}`; | ||
const attachment = Attachment.createWithoutSave(null, user, originalName, this.compressExtension, 0, AttachmentType.PAGE_BULK_EXPORT); | ||
|
||
const fileUploadService: FileUploader = this.crowi.fileUploadService; | ||
|
||
pageArchiver.directory(this.getTmpOutputDir(pageBulkExportJob), false); | ||
pageArchiver.finalize(); | ||
this.setStreamInExecution(pageBulkExportJob._id, pageArchiver); | ||
|
||
try { | ||
await fileUploadService.uploadAttachment(pageArchiver, attachment); | ||
} | ||
catch (e) { | ||
logger.error(e); | ||
this.handleError(e, pageBulkExportJob); | ||
} | ||
await postProcess.bind(this)(pageBulkExportJob, attachment, pageArchiver.pointer()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multipart upload の準備のエラーをキャッチするために await していたが、multipart upload しなくなったため await を除外。
(また、await してしまうと、compressAndUpload 内の uploadAttachment を待つようになってしまう