2021-05-08 02:56:21 -07:00
|
|
|
import * as Bull from 'bull';
|
2021-08-19 02:33:41 -07:00
|
|
|
import config from '@/config/index.js';
|
2021-03-17 19:17:05 -07:00
|
|
|
|
2021-05-08 02:56:21 -07:00
|
|
|
export function initialize<T>(name: string, limitPerSec = -1) {
|
|
|
|
return new Bull<T>(name, {
|
2021-03-17 19:17:05 -07:00
|
|
|
redis: {
|
|
|
|
port: config.redis.port,
|
|
|
|
host: config.redis.host,
|
|
|
|
password: config.redis.pass,
|
|
|
|
db: config.redis.db || 0,
|
|
|
|
},
|
|
|
|
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : 'queue',
|
|
|
|
limiter: limitPerSec > 0 ? {
|
|
|
|
max: limitPerSec * 5,
|
|
|
|
duration: 5000
|
|
|
|
} : undefined
|
|
|
|
});
|
|
|
|
}
|