-
Notifications
You must be signed in to change notification settings - Fork 220
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
enable pdf bulk export #9283
Conversation
|
…o feat/135772-153348-enable-pdf-bulk-export-tsed
…o feat/135772-153348-enable-pdf-bulk-export-tsed
…o feat/135772-153348-enable-pdf-bulk-export-tsed
…o feat/135772-153348-enable-pdf-bulk-export-tsed
…48-enable-pdf-bulk-export-tsed
…48-enable-pdf-bulk-export-tsed
…48-enable-pdf-bulk-export-tsed
.toString(); | ||
|
||
return htmlString; | ||
} |
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.
remark().use(html)
で得られるインスタンスは保持して使い回した方がいいんじゃないかな
どこまで差が出るかはわからないけど
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.
対応しました。
インスタンス変数にして全ての job で共通にするのは並列で処理が走ったときバグる可能性があるように思えたので、ジョブごとに stream 開始前に定義して引数として渡す形にしました。
引数の型ですが、remark().use(html) の返り値の type が unified のものですが、
unified.Processor<remark.RemarkOptions>
remark が依存している unified と growi が package.json で指定している unified のバージョンが異なるっぽくて、同様の type を付与するとエラーが生じてしまいます。
そのため引数に type は付与していません。
(バージョンを対応させようとすると、esm only の remark 系のパッケージが必要となり、エラーが生じてしまいます)
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.
- 使われるバージョンが一致するように別タスクで処理した方がいいように思う
- サーバーサイドでの ESM only package のインポートは、
dynamic-import
で対応できるimport { dynamicImport } from '@cspell/dynamic-import';
でソース内検索
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.
apps/app/src/features/page-bulk-export/server/service/page-bulk-export/index.ts
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() => { |
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.
この 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 することを期待
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.
https://redmine.weseek.co.jp/issues/158220 で service を cron 化し、pdf 化の処理については request-pdf-converter 内に記載し、cron 内で呼び出すように実装しました。
.toString(); | ||
|
||
return htmlString; | ||
} |
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.
- 使われるバージョンが一致するように別タスクで処理した方がいいように思う
- サーバーサイドでの ESM only package のインポートは、
dynamic-import
で対応できるimport { dynamicImport } from '@cspell/dynamic-import';
でソース内検索
…48-enable-pdf-bulk-export-tsed
…48-enable-pdf-bulk-export-tsed
…48-enable-pdf-bulk-export-tsed
@@ -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", |
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.
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 の時立ち上げないように設定。
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.
この先この仕様をしらないプログラマがどのサービスの onInit に何を仕込むかわからないから、generate-swagger するためだけのエントリーポイントを作るのがよさそうかなと (後続ストーリーでよい)
|
||
if (pageBulkExportJob.status === PageBulkExportJobStatus.exporting && pageBulkExportJob.format === PageBulkExportFormat.pdf) { | ||
await requestPdfConverter(pageBulkExportJob); | ||
} |
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.
以下の流れを想定
- L166 の非同期実行されている createPageSnapshotsAsync が完了し、status が exporting になる
- cron 実行の度、requestPdfConverter が実行されるようになる
- pdf 変換が完了するまで statusOnPreviousCronExec が同じになるため、L154 より前に実行する必要がある
- ある cron の実行で L169 の exportPagesToFsAsync が非同期で実行される
- 非同期で実行されている exportPagesToFsAsync が完了し、HTML でのエクスポートが完了する
- pdf converter での pdf 変換処理が完了する
- 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", |
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.
この先この仕様をしらないプログラマがどのサービスの onInit に何を仕込むかわからないから、generate-swagger するためだけのエントリーポイントを作るのがよさそうかなと (後続ストーリーでよい)
5fd17c8
into
feat/135772-pdf-page-bulk-export
This pull request has been removed from the queue for the following reason: 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: |
仕様書
https://dev.growi.org/66ee8495830566b31e02c953#growi
task
https://redmine.weseek.co.jp/issues/153348
備考