-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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: add Subscription #1469
feat: add Subscription #1469
Conversation
@popomore 这个也要发掉了,不然 egg-schedule 的新用户按文档写会报错 |
ping |
43f0d5c
to
1b121dc
Compare
Codecov Report
@@ Coverage Diff @@
## master #1469 +/- ##
==========================================
+ Coverage 99.71% 99.72% +<.01%
==========================================
Files 29 29
Lines 714 715 +1
==========================================
+ Hits 712 713 +1
Misses 2 2
Continue to review full report at Codecov.
|
bf61f7f
to
a3f6407
Compare
@atian25 看看 |
docs/source/en/basics/objects.md
Outdated
const Subscription = require('egg').Subscription; | ||
class Schedule extends Subscription { | ||
// This method should be implemented | ||
* subscribe() {} |
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.
这里可以是 generator / promise / 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.
是的
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.
嗯,所以文档要注明下?
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.
subscribe
could be generator / async function
docs/source/zh-cn/basics/objects.md
Outdated
@@ -270,6 +270,22 @@ module.exports = { | |||
|
|||
我们可以在 Controller 和 Service 实例上通过 `this.logger` 获取到它们,它们本质上就是一个 Context Logger,不过在打印日志的时候还会额外的加上文件路径,方便定位日志的打印位置。 | |||
|
|||
## Subscription | |||
|
|||
Subscription 是一种订阅模型,消息中间件的消费者或调度任务都属于这种模式。 |
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.
订阅模型是一种比较常见的开发模式,譬如消息中间件的消费者或调度任务。因此我们提供了 Subscription 基类来规范化这个模式。
使用方式如下:
...
...
...
开发者可以根据自己的需求,基于它定制特定的订阅规范,如 [定时任务](./schedule.md) 就是使用这种模式实现的,建议开发者可以参考来实现自己的消息中间件。
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.
+1
Checklist
npm test
passesAffected core subsystem(s)
Description of change
Ref #1468