-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
42 lines (33 loc) · 1.02 KB
/
app.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Author: 卓文理
* Email: [email protected]
* Date: 2020-09-02 11:08:45
*/
import { Application } from 'egg';
import Queue = require('bull');
export default async (app: Application) => {
const config = app.config.bull;
if (!config) {
throw new Error('please config bull in config file');
}
app.addSingleton('bull', (config: any, app: Application) => {
const { name, redis } = config;
if (!name) {
app.logger.error('[egg-bull]', 'name is required on config');
return;
}
if (!redis || !redis.host || !redis.port) {
app.logger.error('[egg-bull]', 'host and port of redis are required on config');
return;
}
const queue = new Queue(name, config);
queue.on('error', error => {
app.logger.error(error);
process.exit(1);
});
app.beforeStart(() => {
app.logger.info(`[egg-bull] ${name} 连接成功`);
});
return queue;
});
};