-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(egg): fallback runtime diagnostic config #5933
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,9 +200,12 @@ export class Application extends EggApplicationCore { | |
| super.dumpConfig(); | ||
|
|
||
| // dump routers to router.json | ||
| const rundir = this.config.rundir; | ||
| const rundir = this.getRuntimeRundir(); | ||
| const FULLPATH = this.loader.FileLoader.FULLPATH; | ||
| try { | ||
| if (!fs.existsSync(rundir)) { | ||
| fs.mkdirSync(rundir, { recursive: true }); | ||
| } | ||
| const dumpRouterFile = path.join(rundir, 'router.json'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This directory creation logic is redundant because const dumpRouterFile = path.join(rundir, 'router.json'); |
||
| const routers = []; | ||
| for (const layer of this.router.stack) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,8 @@ import { convertObject, createTransparentProxy } from './core/utils.ts'; | |
| import type { EggApplicationLoader } from './loader/index.ts'; | ||
| import type { EggAppConfig } from './types.ts'; | ||
|
|
||
| const DEFAULT_WORKER_START_TIMEOUT = 10 * 60 * 1000; | ||
|
|
||
| export interface EggApplicationCoreOptions extends Omit<EggCoreOptions, 'baseDir'> { | ||
| mode?: 'cluster' | 'single'; | ||
| clusterPort?: number; | ||
|
|
@@ -565,10 +567,10 @@ export class EggApplicationCore extends EggCore { | |
| * @private | ||
| */ | ||
| dumpConfig(): void { | ||
| const rundir = this.config.rundir; | ||
| const rundir = this.getRuntimeRundir(); | ||
|
killagu marked this conversation as resolved.
|
||
| try { | ||
| if (!fs.existsSync(rundir)) { | ||
| fs.mkdirSync(rundir); | ||
| fs.mkdirSync(rundir, { recursive: true }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // get dumped object | ||
|
|
@@ -589,7 +591,10 @@ export class EggApplicationCore extends EggCore { | |
| dumpTiming(): void { | ||
| try { | ||
| const items = this.timing.toJSON(); | ||
| const rundir = this.config.rundir; | ||
| const rundir = this.getRuntimeRundir(); | ||
| if (!fs.existsSync(rundir)) { | ||
| fs.mkdirSync(rundir, { recursive: true }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const dumpFile = path.join(rundir, `${this.type}_timing_${process.pid}.json`); | ||
| fs.writeFileSync(dumpFile, CircularJSON.stringify(items, null, 2)); | ||
| this.coreLogger.info(this.timing.toString()); | ||
|
|
@@ -641,9 +646,10 @@ export class EggApplicationCore extends EggCore { | |
| } | ||
|
|
||
| #setupTimeoutTimer(): void { | ||
| const workerStartTimeout = this.getWorkerStartTimeout(); | ||
| const startTimeoutTimer = setTimeout(() => { | ||
| this.coreLogger.error(this.timing.toString()); | ||
| this.coreLogger.error(`${this.type} still doesn't ready after ${this.config.workerStartTimeout} ms.`); | ||
| this.coreLogger.error(`${this.type} still doesn't ready after ${workerStartTimeout} ms.`); | ||
|
killagu marked this conversation as resolved.
|
||
| // log unfinished | ||
| const items = this.timing.toJSON(); | ||
| for (const item of items) { | ||
|
|
@@ -658,10 +664,26 @@ export class EggApplicationCore extends EggCore { | |
| this.emit('startTimeout'); | ||
| this.dumpConfig(); | ||
| this.dumpTiming(); | ||
| }, this.config.workerStartTimeout); | ||
| }, workerStartTimeout); | ||
| this.ready(() => clearTimeout(startTimeoutTimer)); | ||
| } | ||
|
|
||
| protected getRuntimeRundir(): string { | ||
| const rundir = this.config.rundir; | ||
| if (typeof rundir === 'string' && rundir.length > 0) { | ||
| return rundir; | ||
| } | ||
| return path.join(this.baseDir, 'run'); | ||
| } | ||
|
killagu marked this conversation as resolved.
|
||
|
|
||
| private getWorkerStartTimeout(): number { | ||
| const workerStartTimeout = this.config.workerStartTimeout; | ||
| if (typeof workerStartTimeout === 'number' && Number.isFinite(workerStartTimeout)) { | ||
|
|
||
| return workerStartTimeout; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return DEFAULT_WORKER_START_TIMEOUT; | ||
| } | ||
|
|
||
| get config() { | ||
| return super.config as EggAppConfig; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.