-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
app.setup() should be async #853
Comments
It should indeed and will probably be addressed at the same time as #509 |
Yes. This is related to feathersjs-ecosystem/commons#72. Basically Even though it isn't really a big API change it'd unfortunately be a breaking change ( |
@daffl I understand. I think this would justify the jump to v4, it's quite important. |
Last week I got bitten too: my app ran smoothly, but its tests threw errors when re-building the database in the before hook of mocha. The problem with the generated Sequelize adapter is that it calls Here is my workaround (without changing what src/sequelize.js - sequelize.sync();
+ app.set('sequelizeSync', sequelize.sync()); src/index.js - server.on('listening', () =>
- logger.info('Feathers application started on http://%s:%d', app.get('host'), port)
- );
+ server.on('listening', () => {
+ app.get('sequelizeSync')
+ .then(() => logger.info('Feathers application started on http://%s:%d', app.get('host'), port))
+ .catch(reason => {
+ console.log(reason);
+ process.exit(1);
+ });
+ }); |
One way to achieve this without breaking the existing This has the additional advantage of:
How does it work: consider a simple service that loads some data over network and provides services on top of it, as below:
When
When When services are dependent on each other, with the help of built-in retries they could wait for the dependency service to become available before proceeding (i.e. keep retrying while Since the
or something like
When many microservices are interacting with each other with complex dependencies, this kind of self-regulation and dependency-based regulation creates flexibility to the designer since it allows them to control the life-time and availability of a service at the granular level. To achieve this above, Feathers, as a framework, has to:
|
I have feathers app that uses sequelize for storage. For the tests, I use sqlite database, which is removed before the test starts, and is created in sequelize.js file as generated by feathers generate service. This all worked fine until the number of models increased beyond 10 ( the number is dependent on how fast the machine is). Now every time I run the full test suite the first couple of tests fail because the DB sync hasn't completed yet and it happens so that the first tests that get ran are the last tables being created.
As a simple workaround , I changed the before of app.test.js(it's the first test being executed) like so :
This fixes it for now until the number of models grows of the test is executed on a slower machine.
The real problem is that app.listen() calls app.setup(), but doesn't wait for it to complete before firing the listening event. The database is created in app.setup and can take some time.
I think app.setup() should be async and app.listen() should wait for it to complete, or else there will always be possibility for race conditions between setup() and service requiring the setup() to complete before it's functional.
The text was updated successfully, but these errors were encountered: