-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(pooling): add an extension to provide pooling service #5681
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
Conversation
f600efe to
f2ef1ac
Compare
|
+1 to implement this as an experimental extension. I don't have bandwidth to review the proposal. Can you @raymondfeng please pick somebody from the team to become a co-owner of the new package and let that person review the initial version. |
f42a945 to
92f9fbd
Compare
92f9fbd to
6e027ed
Compare
9fb50ec to
c7e0470
Compare
| }); | ||
|
|
||
| it('acquires/releases a resource from the pool', async () => { | ||
| const poolService = await givenPoolService({max: 5}); |
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.
Why not leave it out {max: 5}? It makes it look like the test has something to do with the parameter, when it is not. Same applies to other locations.
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.
Removed.
|
|
||
| it('acquires/releases a resource from the pool', async () => { | ||
| const poolService = await givenPoolService({max: 5}); | ||
| poolService.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.
poolService.start(); is not called in some places. How does it work? This behavior should be documented.
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.
My assumption is that poolService will not be usable for anything (eg: poolService.run) unless it is started.
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.
Quoted from generic-pool:
autostart: boolean, should the pool start creating resources, initialize the evictor, etc once the constructor is called. If false, the pool can be started by calling pool.start, otherwise the first call to acquire will start the pool. (default true)
extensions/pooling/src/__tests__/acceptance/pooling.acceptance.ts
Outdated
Show resolved
Hide resolved
| function invokePoolableMethod(resource: Poolable, method: keyof Poolable) { | ||
| if (typeof resource[method] === 'function') { | ||
| return resource[method]!(); | ||
| } |
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.
else: should we throw an error? Failing silently (eg: in case of a typo) doesn't sound good to me.
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.
Not really in this case as the hook method can be optional. I added more debug statements.
| this.pool = createPool(factory, { | ||
| max: 8, // Default to 8 instances | ||
| ...this.options.poolOptions, | ||
| autostart: false, |
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.
If autostart is to be configurable, it must be specified before ...this.options.poolOptions.
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.
I intentionally disable autostart to fit into our life cycles. Added more comments in the code.
extensions/pooling/src/__tests__/acceptance/pooling.acceptance.ts
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1 @@ | |||
| # Unit tests | |||
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.
How about some unit tests?
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.
The pooling service is a wrapper of generic-pool. I believe the extra functions have been covered by the acceptance tests.
|
Looks mostly good, left some comments. |
c7e0470 to
cbfed3e
Compare
|
@hacksparrow Thank you for the comments. PTAL. |
hacksparrow
left a comment
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.
LGTM
cbfed3e to
cea6b6e
Compare
https://github.com/strongloop/loopback-next/blob/binding-pool/extensions/pooling/README.md
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈