feat: support boot lifecyle#2972
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2972 +/- ##
==========================================
+ Coverage 99.75% 99.75% +<.01%
==========================================
Files 29 29
Lines 826 830 +4
==========================================
+ Hits 824 828 +4
Misses 2 2
Continue to review full report at Codecov.
|
| `beforeClose` 注册方法在 app/agent 实例的 `close` 方法被调用后, 按注册的逆序执行。一般用于资源的释放操作, 例如 [`egg`](https://github.com/eggjs/egg/blob/master/lib/egg.js) 用来关闭 logger , 删除监听方法等。 | ||
|
|
||
| __这个方法不建议在生产环境使用, 可能遇到未执行完就结束进程的问题。__ | ||
| Egg提供了配置文件加载完成(`configDidLoad`), 文件加载完成(`didLoad`), 插件启动完毕(`willReady`), worker 准备就绪(`didReady`), 应用启动完成(`serverDidReady`), 应用即将关闭(`beforeClose`)这些生命周期函数。 |
|
|
||
| app before start 100ms: 147.546ms | ||
| app before start 200ms: 245.405ms // 并行执行 | ||
| 使用 `beforeClose` 的时候需要注意,在 egg 的 进程关闭处理中是有超时时间的,如果 worker 进程在接收到进程退出信号之后,没有在所规定的时间内退出,将会被强制关闭。 |
| 如果需要调整超时时间的话,查看[此处文档](https://github.com/eggjs/egg-cluster)。 | ||
|
|
||
| app ready | ||
| Deprecate methods: |
There was a problem hiding this comment.
- 中文
- 另外,既然是 Deprecate,那他们分别的替代方式,可以描述下
| console.timeEnd('app before close 100ms'); | ||
| }); | ||
| // app.js or agent.js | ||
| class AppBootHook { |
There was a problem hiding this comment.
这里没有说明清楚,定义这个类能干嘛,然后在应用层如何给挂载给 egg
| module.exports = AppBootHook; | ||
| ``` | ||
|
|
||
| 开发者使用类的方式定义 `app.js` 和 `agent.js` 之后, 框架会自动加载并实例化这个类, 并且在各个生命周期阶段调用对应的方法。 |
There was a problem hiding this comment.
那之前在里面操作 app.coreMiddleware 的应该放在哪个 method 里面?
是不是写个 old app.js 和 new app.js 的对比
There was a problem hiding this comment.
应该要放在 configDidLoad 里面
There was a problem hiding this comment.
具体还是看我贴的那个图比较清楚。文字描述比较困难。
|
修复下 |
| 如果需要调整超时时间的话,查看[此处文档](https://github.com/eggjs/egg-cluster)。 | ||
|
|
||
| agent ready | ||
| 启用的方法: |
There was a problem hiding this comment.
🤦♂️错别字。本来想写的是 弃用的方法。
7873b33 to
614c194
Compare
|
@atian25 合了吧? |
|
其实放到 https://eggjs.org/zh-cn/basics/app-start.html 才合适,回头我看看怎么写吧 |
|
另外,这个文档对应的英文版也需要更新 |
Refs: #2520
Checklist
npm testpassesAffected core subsystem(s)
loader
Description of change
support load boot hook