-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathagent.js
More file actions
28 lines (22 loc) · 780 Bytes
/
agent.js
File metadata and controls
28 lines (22 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const { chalk } = require('xutil');
const socket = require('./app/socket');
module.exports = agent => {
agent.logger.info(`${chalk.cyan('launch datahub at:')} ${agent.config.sequelize.storage}`);
agent.beforeStart(async () => {
socket.listen(agent.config.dataHubSocket.port);
const exportArchiveBaseDir = agent.config.exportArchiveBaseDir;
if (exportArchiveBaseDir) {
await agent.model.sync({ force: true });
}
});
agent.messenger.once('egg-ready', () => {
const exportArchiveBaseDir = agent.config.exportArchiveBaseDir;
if (exportArchiveBaseDir) {
agent.messenger.sendRandom('worker_import_data', exportArchiveBaseDir);
}
});
agent.messenger.on('emit_socket_data', data => {
socket.emit(data);
});
};