Improve queue option

This commit is contained in:
syuilo 2019-02-06 15:01:43 +09:00
parent 4f2d52697d
commit 9835945ee1
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 32 additions and 18 deletions

View file

@ -5,6 +5,7 @@ program
.version(pkg.version) .version(pkg.version)
.option('--no-daemons', 'Disable daemon processes (for debbuging)') .option('--no-daemons', 'Disable daemon processes (for debbuging)')
.option('--disable-clustering', 'Disable clustering') .option('--disable-clustering', 'Disable clustering')
.option('--disable-ap-queue', 'Disable creating job queue related to ap')
.option('--disable-queue', 'Disable job queue processing') .option('--disable-queue', 'Disable job queue processing')
.option('--only-queue', 'Pocessing job queue only') .option('--only-queue', 'Pocessing job queue only')
.option('--quiet', 'Suppress all logs') .option('--quiet', 'Suppress all logs')
@ -13,6 +14,7 @@ program
.option('--color', 'This option is a dummy for some external program\'s (e.g. forever) issue.') .option('--color', 'This option is a dummy for some external program\'s (e.g. forever) issue.')
.parse(process.argv); .parse(process.argv);
if (process.env.MK_DISABLE_AP_QUEUE) program.disableApQueue = true;
if (process.env.MK_DISABLE_QUEUE) program.disableQueue = true; if (process.env.MK_DISABLE_QUEUE) program.disableQueue = true;
if (process.env.MK_ONLY_QUEUE) program.onlyQueue = true; if (process.env.MK_ONLY_QUEUE) program.onlyQueue = true;

View file

@ -1,6 +1,7 @@
import * as Queue from 'bee-queue'; import * as Queue from 'bee-queue';
import config from '../config'; import * as httpSignature from 'http-signature';
import config from '../config';
import { ILocalUser } from '../models/user'; import { ILocalUser } from '../models/user';
import { program } from '../argv'; import { program } from '../argv';
import handler from './processors'; import handler from './processors';
@ -31,10 +32,19 @@ function initializeQueue() {
} }
} }
export function createHttpJob(data: any) { export function deliver(user: ILocalUser, content: any, to: any) {
if (queueAvailable) { if (content == null) return;
const data = {
type: 'deliver',
user,
content,
to
};
if (queueAvailable && !program.disableApQueue) {
return queue.createJob(data) return queue.createJob(data)
.retries(3) .retries(8)
.backoff('exponential', 1000) .backoff('exponential', 1000)
.save(); .save();
} else { } else {
@ -42,15 +52,21 @@ export function createHttpJob(data: any) {
} }
} }
export function deliver(user: ILocalUser, content: any, to: any) { export function processInbox(activity: any, signature: httpSignature.IParsedSignature) {
if (content == null) return; const data = {
type: 'processInbox',
activity: activity,
signature
};
createHttpJob({ if (queueAvailable && !program.disableApQueue) {
type: 'deliver', return queue.createJob(data)
user, .retries(3)
content, .backoff('exponential', 500)
to .save();
}); } else {
return handler({ data }, () => {});
}
} }
export function createExportNotesJob(user: ILocalUser) { export function createExportNotesJob(user: ILocalUser) {

View file

@ -3,7 +3,6 @@ import * as Router from 'koa-router';
import * as json from 'koa-json-body'; import * as json from 'koa-json-body';
import * as httpSignature from 'http-signature'; import * as httpSignature from 'http-signature';
import { createHttpJob } from '../queue';
import { renderActivity } from '../remote/activitypub/renderer'; import { renderActivity } from '../remote/activitypub/renderer';
import Note from '../models/note'; import Note from '../models/note';
import User, { isLocalUser, ILocalUser, IUser } from '../models/user'; import User, { isLocalUser, ILocalUser, IUser } from '../models/user';
@ -17,6 +16,7 @@ import Followers from './activitypub/followers';
import Following from './activitypub/following'; import Following from './activitypub/following';
import Featured from './activitypub/featured'; import Featured from './activitypub/featured';
import renderQuestion from '../remote/activitypub/renderer/question'; import renderQuestion from '../remote/activitypub/renderer/question';
import { processInbox } from '../queue';
// Init router // Init router
const router = new Router(); const router = new Router();
@ -35,11 +35,7 @@ function inbox(ctx: Router.IRouterContext) {
return; return;
} }
createHttpJob({ processInbox(ctx.request.body, signature);
type: 'processInbox',
activity: ctx.request.body,
signature
});
ctx.status = 202; ctx.status = 202;
} }