mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-26 22:36:44 -06:00
52 lines
1 KiB
TypeScript
52 lines
1 KiB
TypeScript
import * as Queue from 'bee-queue';
|
|
import config from '../config';
|
|
import http from './processors/http';
|
|
import { ILocalUser } from '../models/user';
|
|
import Logger from '../misc/logger';
|
|
import { program } from '../argv';
|
|
|
|
const enableQueue = config.redis != null && !program.disableQueue;
|
|
|
|
const queue = new Queue('misskey', {
|
|
redis: {
|
|
port: config.redis.port,
|
|
host: config.redis.host,
|
|
password: config.redis.pass
|
|
},
|
|
|
|
removeOnSuccess: true,
|
|
removeOnFailure: true,
|
|
getEvents: false,
|
|
sendEvents: false,
|
|
storeJobs: false
|
|
});
|
|
|
|
export function createHttpJob(data: any) {
|
|
if (enableQueue) {
|
|
return queue.createJob(data)
|
|
.retries(4)
|
|
.backoff('exponential', 16384) // 16s
|
|
.save();
|
|
} else {
|
|
return http({ data }, () => {});
|
|
}
|
|
}
|
|
|
|
export function deliver(user: ILocalUser, content: any, to: any) {
|
|
if (content == null) return;
|
|
|
|
createHttpJob({
|
|
type: 'deliver',
|
|
user,
|
|
content,
|
|
to
|
|
});
|
|
}
|
|
|
|
export const queueLogger = new Logger('queue');
|
|
|
|
export default function() {
|
|
if (enableQueue) {
|
|
queue.process(128, http);
|
|
}
|
|
}
|