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

enable pdf bulk export #9283

Conversation

arafubeatbox
Copy link
Contributor

@arafubeatbox arafubeatbox commented Oct 20, 2024

仕様書

https://dev.growi.org/66ee8495830566b31e02c953#growi

task

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

備考

  • base branch は feat/page-bulk-export ではなく、feat/135772-pdf-page-bulk-export

Copy link

changeset-bot bot commented Oct 20, 2024

⚠️ No Changeset found

Latest commit: c8d4802

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

Base automatically changed from feat/135772-155547-pdf-converter-tsed-devcontainer to feat/135772-pdf-page-bulk-export November 11, 2024 13:37
@arafubeatbox arafubeatbox marked this pull request as ready for review November 12, 2024 10:39
.toString();

return htmlString;
}
Copy link
Member

Choose a reason for hiding this comment

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

remark().use(html) で得られるインスタンスは保持して使い回した方がいいんじゃないかな
どこまで差が出るかはわからないけど

Copy link
Contributor Author

Choose a reason for hiding this comment

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

対応しました。
インスタンス変数にして全ての job で共通にするのは並列で処理が走ったときバグる可能性があるように思えたので、ジョブごとに stream 開始前に定義して引数として渡す形にしました。

引数の型ですが、remark().use(html) の返り値の type が unified のものですが、

unified.Processor<remark.RemarkOptions>

remark が依存している unified と growi が package.json で指定している unified のバージョンが異なるっぽくて、同様の type を付与するとエラーが生じてしまいます。
そのため引数に type は付与していません。
(バージョンを対応させようとすると、esm only の remark 系のパッケージが必要となり、エラーが生じてしまいます)

Copy link
Member

Choose a reason for hiding this comment

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

  • 使われるバージョンが一致するように別タスクで処理した方がいいように思う
  • サーバーサイドでの ESM only package のインポートは、dynamic-import で対応できる
    • import { dynamicImport } from '@cspell/dynamic-import'; でソース内検索

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/159172
タスク作りました。

apps/app/turbo.json Outdated Show resolved Hide resolved

return new Promise<void>((resolve, reject) => {
// Request sync job API until the pdf export is done. If pdf export status is updated in growi, send the status to pdf-converter.
const interval = setInterval(async() => {
Copy link
Member

@yuki-takei yuki-takei Nov 22, 2024

Choose a reason for hiding this comment

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

この setInterval、job の数だけ走るのはあまりよくない気がする。
setInterval よりシステムワイドに node-cron を使うべきではないか?

また、サーバーが再起動した時に job を参照して再開してほしい。

参考:

  • thread-deletion-cron.ts
  • vector-store-file-deletion-cron.ts

実装アイデアメモ

cronJob は2種類あってもいいかも。

  • 1つは処理完了待ちの job で、10秒とか比較的短いインターバルで動いて fail / done へステータスを遷移させる
  • もう1つは上記の処理完了待ち job の start/stop を担当する (2~3分の長めのインターバルでよい)
    • in progress な job が 1 つでもあれば処理完了待ち job を start させる
    • in progress な job が 0 個なら処理完了待ち job を stop させる
    • サーバー再起動時はこれを start しておくことで、数分後には必要があれば処理完了待ち job が start することを期待

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/158220 で service を cron 化し、pdf 化の処理については request-pdf-converter 内に記載し、cron 内で呼び出すように実装しました。

.toString();

return htmlString;
}
Copy link
Member

Choose a reason for hiding this comment

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

  • 使われるバージョンが一致するように別タスクで処理した方がいいように思う
  • サーバーサイドでの ESM only package のインポートは、dynamic-import で対応できる
    • import { dynamicImport } from '@cspell/dynamic-import'; でソース内検索

@@ -11,7 +11,7 @@
"start:prod:ci": "pnpm start:prod --ci",
"start:prod": "node dist/index.js",
"lint": "pnpm eslint **/*.{js,ts}",
"gen:client-code": "tsed run generate-swagger --output ./specs && orval",
"gen:client-code": "SWAGGER_GENERATION=true tsed run generate-swagger --output ./specs && orval",
Copy link
Contributor Author

@arafubeatbox arafubeatbox Dec 14, 2024

Choose a reason for hiding this comment

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

apps/pdf-converter/src/service/pdf-convert.ts で $onInit で puppeteer を初期化するように変更した結果、tsed run generate-swagger で puppetter のエラー (Error: Unable to launch browser, error message: Could not find Chrome (ver. 130.0.6723.69)) が生じるようになったが、swagger schema 生成に puppeteer の立ち上げは必要ないため、SWAGGER_GENERATION=true の時立ち上げないように設定。

Copy link
Member

Choose a reason for hiding this comment

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

この先この仕様をしらないプログラマがどのサービスの onInit に何を仕込むかわからないから、generate-swagger するためだけのエントリーポイントを作るのがよさそうかなと (後続ストーリーでよい)


if (pageBulkExportJob.status === PageBulkExportJobStatus.exporting && pageBulkExportJob.format === PageBulkExportFormat.pdf) {
await requestPdfConverter(pageBulkExportJob);
}
Copy link
Contributor Author

@arafubeatbox arafubeatbox Dec 14, 2024

Choose a reason for hiding this comment

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

以下の流れを想定

  1. L166 の非同期実行されている createPageSnapshotsAsync が完了し、status が exporting になる
  2. cron 実行の度、requestPdfConverter が実行されるようになる
    • pdf 変換が完了するまで statusOnPreviousCronExec が同じになるため、L154 より前に実行する必要がある
  3. ある cron の実行で L169 の exportPagesToFsAsync が非同期で実行される
  4. 非同期で実行されている exportPagesToFsAsync が完了し、HTML でのエクスポートが完了する
  5. pdf converter での pdf 変換処理が完了する
  6. requestPdfConverter で pdf 変換処理を検知し、status が uploading になる

@@ -11,7 +11,7 @@
"start:prod:ci": "pnpm start:prod --ci",
"start:prod": "node dist/index.js",
"lint": "pnpm eslint **/*.{js,ts}",
"gen:client-code": "tsed run generate-swagger --output ./specs && orval",
"gen:client-code": "SWAGGER_GENERATION=true tsed run generate-swagger --output ./specs && orval",
Copy link
Member

Choose a reason for hiding this comment

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

この先この仕様をしらないプログラマがどのサービスの onInit に何を仕込むかわからないから、generate-swagger するためだけのエントリーポイントを作るのがよさそうかなと (後続ストーリーでよい)

@yuki-takei yuki-takei merged commit 5fd17c8 into feat/135772-pdf-page-bulk-export Dec 16, 2024
10 checks passed
@yuki-takei yuki-takei deleted the feat/135772-153348-enable-pdf-bulk-export-tsed branch December 16, 2024 12:14
Copy link
Contributor

mergify bot commented Dec 16, 2024

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #9283 has been dequeued. The pull request has been merged manually. The pull request has been merged manually at 5fd17c8.

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

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