Skip to content

Commit

Permalink
Load app should correct and middleware should work correct (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
okoala authored Dec 2, 2017
1 parent db66284 commit d584a41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
20 changes: 9 additions & 11 deletions packages/avet-cluster/lib/app_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@ const listenConfig = clusterConfig.listen || /* istanbul ignore next */ {};
const port = (options.port = options.port || listenConfig.port);
process.send({ to: 'master', action: 'realport', data: port });

app.ready(async err => {
if (err) {
console.error(err);
console.error('[app_worker] start error, exiting with code:1');
process.exit(1);
}

const avetServer = new AvetServer(avetOptions);
await avetServer.prepare();
const avetServer = new AvetServer(avetOptions);

avetServer.prepare().then(() => {
app.use(function*(next) {
yield avetServer.run(this, next);

Expand All @@ -39,7 +32,7 @@ app.ready(async err => {
}
});

startServer();
app.ready(startServer);
});

// exit if worker start timeout
Expand All @@ -49,7 +42,12 @@ function startTimeoutHandler() {
process.exit(1);
}

function startServer() {
function startServer(err) {
if (err) {
console.error(err);
console.error('[app_worker] start error, exiting with code:1');
process.exit(1);
}
app.removeListener('startTimeout', startTimeoutHandler);

let server;
Expand Down
1 change: 0 additions & 1 deletion packages/avet-core/lib/avet.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class AvetCore extends KoaApplication {
);

this._options = options;
this.middleware = [];

const Loader = this[AVET_LOADER];
this.loader = new Loader({
Expand Down
3 changes: 2 additions & 1 deletion packages/avet/lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Agent extends AvetCore {

this.loader.loadPlugin();
this.loader.loadConfig();
this.loader.loadCustomApp();
this.loader.loadCustomAgent();
this.loader.loadExtend();

// keep agent alive even it don't have any io tasks
Expand Down Expand Up @@ -59,6 +59,7 @@ class Agent extends AvetCore {
.split('\n')
.slice(1)
.join('\n');

console.warn(
"agent can't call %s before server started\n%s",
methodName,
Expand Down
2 changes: 1 addition & 1 deletion packages/avet/lib/avet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Application extends AvetCore {

this.loader.loadPlugin();
this.loader.loadConfig();
this.loader.loadCustomAgent();
this.loader.loadCustomApp();
this.loader.loadExtend();

// Listen the error that promise had not catch, then log it in common-error
Expand Down

0 comments on commit d584a41

Please sign in to comment.