From d283ec69f7282440bb5f9f44a69ac7eb6ab3459e Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 7 Mar 2019 23:27:38 +0900 Subject: [PATCH] Refactor --- src/queue/index.ts | 44 ++++++++++---------------------- src/queue/processors/db/index.ts | 6 +++-- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/queue/index.ts b/src/queue/index.ts index bb3b66908d..8912a7abfd 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -62,72 +62,54 @@ export function inbox(activity: any, signature: httpSignature.IParsedSignature) } export function createDeleteNotesJob(user: ILocalUser) { - const data = { - type: 'deleteNotes', + return dbQueue.add('deleteNotes', { user: user - }; - - return dbQueue.add(data, { + }, { removeOnComplete: true, removeOnFail: true }); } export function createDeleteDriveFilesJob(user: ILocalUser) { - const data = { - type: 'deleteDriveFiles', + return dbQueue.add('deleteDriveFiles', { user: user - }; - - return dbQueue.add(data, { + }, { removeOnComplete: true, removeOnFail: true }); } export function createExportNotesJob(user: ILocalUser) { - const data = { - type: 'exportNotes', + return dbQueue.add('exportNotes', { user: user - }; - - return dbQueue.add(data, { + }, { removeOnComplete: true, removeOnFail: true }); } export function createExportFollowingJob(user: ILocalUser) { - const data = { - type: 'exportFollowing', + return dbQueue.add('exportFollowing', { user: user - }; - - return dbQueue.add(data, { + }, { removeOnComplete: true, removeOnFail: true }); } export function createExportMuteJob(user: ILocalUser) { - const data = { - type: 'exportMute', + return dbQueue.add('exportMute', { user: user - }; - - return dbQueue.add(data, { + }, { removeOnComplete: true, removeOnFail: true }); } export function createExportBlockingJob(user: ILocalUser) { - const data = { - type: 'exportBlocking', + return dbQueue.add('exportBlocking', { user: user - }; - - return dbQueue.add(data, { + }, { removeOnComplete: true, removeOnFail: true }); @@ -137,7 +119,7 @@ export default function() { if (!program.onlyServer) { deliverQueue.process(processDeliver); inboxQueue.process(processInbox); - dbQueue.process(processDb); + processDb(dbQueue); } } diff --git a/src/queue/processors/db/index.ts b/src/queue/processors/db/index.ts index 91d7f06a4b..31a176cdae 100644 --- a/src/queue/processors/db/index.ts +++ b/src/queue/processors/db/index.ts @@ -15,6 +15,8 @@ const jobs = { exportBlocking, } as any; -export default function(job: Bull.Job, done: any) { - jobs[job.data.type](job, done); +export default function(dbQueue: Bull.Queue) { + for (const [k, v] of Object.entries(jobs)) { + dbQueue.process(k, v as any); + } }