Skip to content
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

Make avet build to of egg #30

Merged
merged 36 commits into from
Dec 28, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
f
okoala committed Dec 27, 2017
commit 6f53337a8233a62e3fc93b8e73336c13ac094f45
60 changes: 0 additions & 60 deletions packages/avet/lib/agent.js
Original file line number Diff line number Diff line change
@@ -6,77 +6,17 @@ const AVET_PATH = Symbol.for('avet#avetPath');

class Agent extends AvetCore {
constructor(options = {}) {
options.type = 'agent';

super(options);

this.messenger = new Messenger();

this._wrapMessenger();

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

// keep agent alive even it don't have any io tasks
setInterval(() => {}, 24 * 60 * 60 * 1000);

this._uncaughtExceptionHandler = this._uncaughtExceptionHandler.bind(this);
process.on('uncaughtException', this._uncaughtExceptionHandler);
}

_uncaughtExceptionHandler(err) {
if (!(err instanceof Error)) {
err = new Error(String(err));
}
/* istanbul ignore else */
if (err.name === 'Error') {
err.name = 'unhandledExceptionError';
}
console.error(err);
}

get [AVET_PATH]() {
return path.join(__dirname, '..');
}

_wrapMessenger() {
for (const methodName of [
'broadcast',
'sendTo',
'sendToApp',
'sendToAgent',
'sendRandom',
]) {
wrapMethod(methodName, this.messenger);
}

function wrapMethod(methodName, messenger) {
const originMethod = messenger[methodName];
messenger[methodName] = function(...args) {
const stack = new Error().stack
.split('\n')
.slice(1)
.join('\n');

console.warn(
"agent can't call %s before server started\n%s",
methodName,
stack
);
originMethod.apply(this, args);
};
messenger.once('egg-ready', () => {
messenger[methodName] = originMethod;
});
}
}

close() {
process.removeListener('uncaughtException', this._uncaughtExceptionHandler);
return super.close();
}
}

module.exports = Agent;
11 changes: 7 additions & 4 deletions packages/avet/lib/avet.js → packages/avet/lib/application.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const path = require('path');
const { AvetCore } = require('avet-core');
const { AppWorkerLoader } = require('./loader');

const AVET_PATH = Symbol.for('avet#avetPath');
const EGG_LOADER = Symbol.for('egg#loader');

class Application extends AvetCore {
class Application extends AppWorkerLoader {
constructor(options) {
options.type = 'application';

super(options);

this.loader.loadPlugin();
@@ -15,6 +14,10 @@ class Application extends AvetCore {
this.loader.loadAvetExtend();
}

get [EGG_LOADER]() {
return AppWorkerLoader;
}

get [AVET_PATH]() {
return path.join(__dirname, '..');
}
Empty file.
Empty file.
Empty file.