-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9467 from weseek/feat/158222-158279-bulk-export-t…
…o-normal-fs Feat/158222 158279 bulk export for file upload types other than s3/gcs
- Loading branch information
Showing
20 changed files
with
114 additions
and
182 deletions.
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.