Improve queue configuration

Resolve #4157
Resolve #4158
This commit is contained in:
syuilo
2019-02-06 13:51:02 +09:00
parent 08c0be11b2
commit e26bec6ab4
3 changed files with 71 additions and 30 deletions

View File

@ -4,13 +4,15 @@ import config from '../config';
import { ILocalUser } from '../models/user';
import { program } from '../argv';
import handler from './processors';
import { queueLogger } from './logger';
const enableQueue = config.redis != null && !program.disableQueue;
const enableQueue = !program.disableQueue;
const queueAvailable = config.redis != null;
const queue = initializeQueue();
function initializeQueue() {
if (enableQueue) {
if (queueAvailable) {
return new Queue('misskey', {
redis: {
port: config.redis.port,
@ -30,7 +32,7 @@ function initializeQueue() {
}
export function createHttpJob(data: any) {
if (enableQueue) {
if (queueAvailable) {
return queue.createJob(data)
.retries(4)
.backoff('exponential', 16384) // 16s
@ -52,7 +54,7 @@ export function deliver(user: ILocalUser, content: any, to: any) {
}
export function createExportNotesJob(user: ILocalUser) {
if (!enableQueue) throw 'queue disabled';
if (!queueAvailable) throw 'queue unavailable';
return queue.createJob({
type: 'exportNotes',
@ -62,7 +64,10 @@ export function createExportNotesJob(user: ILocalUser) {
}
export default function() {
if (enableQueue) {
if (queueAvailable && enableQueue) {
queue.process(128, handler);
queueLogger.succ('Processing started');
}
return queue;
}