-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const BaseHookClass = require('./lib/core/base_hook_class'); | ||
|
||
class EggAgentHook extends BaseHookClass { | ||
configDidLoad() { | ||
this.agent._wrapMessenger(); | ||
} | ||
} | ||
|
||
module.exports = EggAgentHook; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const INSTANCE = Symbol('BaseHookClass#instance'); | ||
|
||
class BaseHookClass { | ||
|
||
constructor(instance) { | ||
this[INSTANCE] = instance; | ||
} | ||
|
||
get logger() { | ||
return this[INSTANCE].logger; | ||
} | ||
|
||
get config() { | ||
return this[INSTANCE].config; | ||
} | ||
|
||
get app() { | ||
assert(this[INSTANCE].type === 'application', 'agent boot should not use app instance'); | ||
return this[INSTANCE]; | ||
} | ||
|
||
get agent() { | ||
assert(this[INSTANCE].type === 'agent', 'app boot should not use agent instance'); | ||
return this[INSTANCE]; | ||
} | ||
} | ||
|
||
module.exports = BaseHookClass; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ | |
"lib", | ||
"app", | ||
"config", | ||
"agent.js", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const mock = require('egg-mock'); | ||
const path = require('path'); | ||
const utils = require('./utils'); | ||
|
||
describe('test/agent.test.js', () => { | ||
afterEach(mock.restore); | ||
let app; | ||
|
||
before(() => { | ||
app = utils.app('apps/agent-logger-config'); | ||
return app.ready(); | ||
}); | ||
after(() => app.close()); | ||
|
||
it('agent logger config should work', () => { | ||
const fileTransport = app._agent.logger.get('file'); | ||
assert(fileTransport.options.file === path.join('/tmp/foo', 'egg-agent.log')); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/fixtures/apps/agent-logger-config/config/config.default.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
logger: { | ||
dir: '/tmp/foo', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "agent-logger-config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const sleep = require('mz-modules/sleep'); | ||
const BaseHookClass = require('../../../../lib/core/base_hook_class'); | ||
|
||
module.exports = class { | ||
constructor(app) { | ||
app.bootLog = []; | ||
this.app = app; | ||
module.exports = class extends BaseHookClass { | ||
constructor(agent) { | ||
super(agent); | ||
agent.bootLog = []; | ||
assert(this.config); | ||
} | ||
|
||
configDidLoad() { | ||
this.app.bootLog.push('configDidLoad'); | ||
this.agent.bootLog.push('configDidLoad'); | ||
} | ||
|
||
async didLoad() { | ||
await sleep(1); | ||
this.app.bootLog.push('didLoad'); | ||
this.agent.bootLog.push('didLoad'); | ||
} | ||
|
||
async willReady() { | ||
await sleep(1); | ||
this.app.bootLog.push('willReady'); | ||
this.agent.bootLog.push('willReady'); | ||
} | ||
|
||
async didReady() { | ||
await sleep(1); | ||
this.app.bootLog.push('didReady'); | ||
this.agent.bootLog.push('didReady'); | ||
this.logger.info('agent is ready'); | ||
} | ||
|
||
async beforeClose() { | ||
await sleep(1); | ||
this.app.bootLog.push('beforeClose'); | ||
this.agent.bootLog.push('beforeClose'); | ||
} | ||
|
||
async serverDidReady() { | ||
await sleep(1); | ||
this.app.bootLog.push('serverDidReady'); | ||
this.agent.bootLog.push('serverDidReady'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters