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

Feat/78040 135788 resume suspended bulk export job #8963

Conversation

arafubeatbox
Copy link
Contributor

@arafubeatbox arafubeatbox commented Jul 15, 2024

実装内容

  • bulk export を再開可能にする
    • 実行を PageBulkExportJob で管理し、status と lastExportedPagePath によって再開時に実行を開始するポイントを決定
      • status の遷移:
        1. initializing (エクスポートするページのスナップショットを作成中)
        2. exporting (local fs にページファイルを出力中)
        3. uploading (cloud storage にアップロード中)
        4. completed/failed
      • exporting の途中で中断した場合は中断したポイントから再開できるが、initializing と uploading は中断した場合そのステップを再開時に最初からやり直す
    • PageBulkExportJob の再開はアプリ起動時に発火する
  • 既に同じユーザ・ページ・フォーマットでのエクスポートが走っている場合はエクスポートをリクエストできないように変更
    • 本ストーリーのスコープからは外れますが、実装してしまった方が本ストーリーの実装を進める上で考えることが少なくなるので同じ PR で実装してしまいました。
    • 実装としては DuplicateBulkExportJobError を追加してエラーハンドリングを少し変えた程度です
    • https://redmine.weseek.co.jp/issues/150418 で進行中のアップロードを中断して再実行も可能にする予定です (最新の情報で最初からアップロードし直したい場合など)
  • PageBulkExportPageInfo を PageBulkExportPageSnapshot に変更

task

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

Copy link

changeset-bot bot commented Jul 15, 2024

⚠️ No Changeset found

Latest commit: f46858f

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

) {
const activity = await this.crowi.activityService.createActivity({
...activityParameters,
Copy link
Contributor Author

@arafubeatbox arafubeatbox Jul 16, 2024

Choose a reason for hiding this comment

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

ここをどうするか迷ったのですが、再開する時は apps/app/src/crowi/index.js から実行されるため、activityParameters (ip と endpoint) を渡すことができません。

最初のクライアントからの bulk export 実行のリクエスト時に、ip と endpoint をどこかに保存しておいて、createActivity 時に渡すべきでしょうか?

正直 ip と endpoint の用途があまりわかっていませんが、ログ的な役割だと思っています。
裏で走っている非同期プロセス上でアプリが activity を行い、クライアントが直接 activity を行ったわけではない、という風に捉えれば、ip と endpoint は入れなくても良いのかなと思ったりしています (今はそのように実装しています)。

Copy link
Member

Choose a reason for hiding this comment

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

action のタイプを、ユーザーが export をトリガーしたときとシステムが再開をトリガーしたときで分けちゃえばいいんじゃないかな。ユーザーがトリガーした時はやはり ip 欲しいので。

逆にシステムによるトリガーはログとしての activity はそんなに重要ではない
InAppNotification の方に影響がないならば記録しなくてもいい

Copy link
Contributor Author

Choose a reason for hiding this comment

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

activityParameters を optional にし、API 経由で直接実行された時だけ渡すようにしましたm(_ _)m

Copy link
Contributor Author

Choose a reason for hiding this comment

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

逆にシステムによるトリガーはログとしての activity はそんなに重要ではない
InAppNotification の方に影響がないならば記録しなくてもいい

InAppNotification に影響はないため、システムからのトリガーでは渡さなくて問題ありません。

@arafubeatbox arafubeatbox marked this pull request as ready for review July 16, 2024 09:35
});
if (duplicatePageBulkExportJobInProgress != null) {
throw new DuplicateBulkExportJobError();
}
Copy link
Contributor Author

@arafubeatbox arafubeatbox Aug 7, 2024

Choose a reason for hiding this comment

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

同じページに対して、進行中のエクスポートジョブがある場合はエラーを投げる。

throw new DuplicateBulkExportJobError();
}
const pageBulkExportJob: PageBulkExportJobDocument & HasObjectId = await PageBulkExportJob.create({
user: currentUser, page: basePage, format, status: PageBulkExportJobStatus.initializing,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

エクスポートの実行を追うための PageBulkExportJob を作成

],
});
Promise.all(jobs.map(job => pageBulkExportService.executePageBulkExportJob(job)));
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

起動時に進行中の PageBulkExportJob を再開

Copy link
Member

Choose a reason for hiding this comment

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

ペンディング中の job 数は予測ができない。
多すぎる場合に Promise.all ではリソースを食い潰すので、擬似的にでもキューイングのようなことをしたい。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

こちら
https://redmine.weseek.co.jp/issues/143599
で対応しようと思います。
TODO コメント残しておきました。

) {
const activity = await this.crowi.activityService.createActivity({
...activityParameters,
Copy link
Member

Choose a reason for hiding this comment

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

action のタイプを、ユーザーが export をトリガーしたときとシステムが再開をトリガーしたときで分けちゃえばいいんじゃないかな。ユーザーがトリガーした時はやはり ip 欲しいので。

逆にシステムによるトリガーはログとしての activity はそんなに重要ではない
InAppNotification の方に影響がないならば記録しなくてもいい

],
});
Promise.all(jobs.map(job => pageBulkExportService.executePageBulkExportJob(job)));
};
Copy link
Member

Choose a reason for hiding this comment

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

ペンディング中の job 数は予測ができない。
多すぎる場合に Promise.all ではリソースを食い潰すので、擬似的にでもキューイングのようなことをしたい。

@yuki-takei yuki-takei merged commit 2591f22 into feat/page-bulk-export Aug 13, 2024
5 checks passed
@yuki-takei yuki-takei deleted the feat/78040-135788-resume-suspended-bulk-export-job branch August 13, 2024 07:54
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