summaryrefslogtreecommitdiff
path: root/src/queue
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-02-04 13:35:58 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-02-04 13:35:58 +0900
commitd3b3426ebe6f38093e23c57b6b11df4200b46a0a (patch)
tree9064c06ee6e0ec40abc39c2fed2945064fd12ed9 /src/queue
parentAdd --verbose option (diff)
downloadsharkey-d3b3426ebe6f38093e23c57b6b11df4200b46a0a.tar.gz
sharkey-d3b3426ebe6f38093e23c57b6b11df4200b46a0a.tar.bz2
sharkey-d3b3426ebe6f38093e23c57b6b11df4200b46a0a.zip
Enable job queue
Resolve #3216
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/index.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/queue/index.ts b/src/queue/index.ts
index 431d4cb3e5..5e5f9dae48 100644
--- a/src/queue/index.ts
+++ b/src/queue/index.ts
@@ -1,9 +1,34 @@
+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';
+const enableQueue = config.redis != null;
+
+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) {
- return http({ data }, () => {});
+ 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) {
@@ -18,3 +43,9 @@ export function deliver(user: ILocalUser, content: any, to: any) {
}
export const queueLogger = new Logger('queue');
+
+export default function() {
+ if (enableQueue) {
+ queue.process(128, http);
+ }
+}