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

Imprv/158220 158223 add page bulk export job cron #9461

Conversation

arafubeatbox
Copy link
Contributor

@arafubeatbox arafubeatbox commented Dec 1, 2024

実装内容

  • 既存の PageBulkExportJobCron (終了/失敗した PageBulkExportJob の clean up を担当) を PageBulkExportJobCleanUpCron に変更
  • PageBulkExportService の PageBulkExportJob 実行部分を PageBulkExportJobCron として抽出
    • 実行内容: 実行中のステータス (initializing, exporting, uploading) の PageBulkExportJob を探し出し、実行可能であれば次の実行ステップを開始する
      • PageBulkExportJob は古いものから順に n 件 (parallelExecLimit) に絞っている
    • initializing, exporting, uploading のステップで実行する内容はそれぞれ個別ファイルに抽出している
      • initializing: create-page-snapshots-async.ts
      • exporting: export-pages-to-fs-async.ts
      • uploading: compress-and-upload-async.ts
    • 10 秒おきに実行する。ただし、進行中の PageBulkExportJob がない場合は CheckPageBulkExportJobInProgressCronService によって停止される
    • PageBulkExportService の内容の変更は Imprv/158220 158276 clean up page bulk export service #9460 で行っている
  • CheckPageBulkExportJobInProgressCronService を追加
    • 3分おきに進行中の PageBulkExportJob があるかを確認し、ある場合は PageBulkExportJobCron を開始、ない場合は PageBulkExportJobCron を停止

task

https://redmine.weseek.co.jp/issues/158223

Copy link

changeset-bot bot commented Dec 1, 2024

⚠️ No Changeset found

Latest commit: 96d2dc1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

*/
getTmpOutputDir(pageBulkExportJob: PageBulkExportJobDocument): string {
return `${this.tmpOutputRootDir}/${pageBulkExportJob._id}`;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PageBulkExportService からの抽出

* @param action whether the export was successful
* @param pageBulkExportJob the page bulk export job
*/
async notifyExportResultAndCleanUp(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PageBulkExportService からの抽出

* - remove the temporal output directory
* - abort multipart upload
*/
async cleanUpExportJobResources(pageBulkExportJob: PageBulkExportJobDocument, restarted = false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PageBulkExportService からの抽出

});
}

private async notifyExportResult(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PageBulkExportService からの抽出

import type { PageBulkExportJobDocument } from '../../../models/page-bulk-export-job';

const logger = loggerFactory('growi:service:page-bulk-export-job-cron:compress-and-upload-async');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

このファイル内の関数は全て PageBulkExportService からの抽出

import type { PageBulkExportJobDocument } from '../../../models/page-bulk-export-job';
import PageBulkExportJob from '../../../models/page-bulk-export-job';
import PageBulkExportPageSnapshot from '../../../models/page-bulk-export-page-snapshot';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

このファイル内の関数は全て PageBulkExportService からの抽出

import type { PageBulkExportJobDocument } from '../../../models/page-bulk-export-job';
import type { PageBulkExportPageSnapshotDocument } from '../../../models/page-bulk-export-page-snapshot';
import PageBulkExportPageSnapshot from '../../../models/page-bulk-export-page-snapshot';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

このファイル内の関数は全て PageBulkExportService からの抽出

@arafubeatbox arafubeatbox marked this pull request as ready for review December 1, 2024 12:39
* Manages cronjob which proceeds PageBulkExportJobs in progress.
* If PageBulkExportJob finishes the current step, the next step will be started on the next cron execution.
*/
class PageBulkExportJobCronService extends CronService implements IPageBulkExportJobCronService {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

executeJob (cronjob の実行対象) で実行される proceedBulkExportJob がキモ。それ以外はほとんど PageBulkExportService からの抽出。

PageBulkExportJob が中断された際に実行中の stream も停止する必要があるため、streamInExecutionMemo を追加 (PageBulkExportService では PageBulkExportJobManager が担っていた)

*/
class PageBulkExportJobCronService extends CronService implements IPageBulkExportJobCronService {

crowi: any;
Copy link
Member

Choose a reason for hiding this comment

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

Crowi 型を参照させてください

this.crowi = crowi;
this.activityEvent = crowi.event('activity');
this.pageModel = mongoose.model<IPage, PageModel>('Page');
this.userModel = mongoose.model<IUser>('User');
Copy link
Member

Choose a reason for hiding this comment

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

mongoose.model() によるモデルオブジェクト取得は、それを利用するメソッドの冒頭で実行してください

@arafubeatbox arafubeatbox merged commit 7f8190c into feat/page-bulk-export Dec 3, 2024
10 checks passed
@arafubeatbox arafubeatbox deleted the imprv/158220-158223-add-page-bulk-export-job-cron branch December 3, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants