From 63906af5ab170ff11f74450fedf980d21aacf49b Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 3 Apr 2018 02:09:50 +0900 Subject: [PATCH] Fix job processor interfaces --- src/processor/http/follow.ts | 4 +-- src/processor/http/perform-activitypub.ts | 5 ++-- src/processor/http/process-inbox.ts | 4 +-- src/processor/http/report-github-failure.ts | 31 +++++++++------------ 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/processor/http/follow.ts b/src/processor/http/follow.ts index cbb7838c68..6b2a39d517 100644 --- a/src/processor/http/follow.ts +++ b/src/processor/http/follow.ts @@ -11,7 +11,7 @@ import context from '../../remote/activitypub/renderer/context'; import render from '../../remote/activitypub/renderer/follow'; import config from '../../config'; -export default ({ data }, done) => Following.findOne({ _id: data.following }).then(({ followerId, followeeId }) => { +export default ({ data }) => Following.findOne({ _id: data.following }).then(({ followerId, followeeId }) => { const promisedFollower = User.findOne({ _id: followerId }); const promisedFollowee = User.findOne({ _id: followeeId }); @@ -104,4 +104,4 @@ export default ({ data }, done) => Following.findOne({ _id: data.following }).th return Promise.all([followerEvent, followeeEvent]); }) ]); -}).then(done, done); +}); diff --git a/src/processor/http/perform-activitypub.ts b/src/processor/http/perform-activitypub.ts index 420ed9ec75..adf4e65a72 100644 --- a/src/processor/http/perform-activitypub.ts +++ b/src/processor/http/perform-activitypub.ts @@ -1,6 +1,5 @@ import User from '../../models/user'; import act from '../../remote/activitypub/act'; -export default ({ data }, done) => User.findOne({ _id: data.actor }) - .then(actor => act(actor, data.outbox, false)) - .then(() => done(), done); +export default ({ data }) => User.findOne({ _id: data.actor }) + .then(actor => act(actor, data.outbox, false)); diff --git a/src/processor/http/process-inbox.ts b/src/processor/http/process-inbox.ts index 78c20f8a7e..11801409cc 100644 --- a/src/processor/http/process-inbox.ts +++ b/src/processor/http/process-inbox.ts @@ -4,7 +4,7 @@ import User, { IRemoteUser } from '../../models/user'; import act from '../../remote/activitypub/act'; import resolvePerson from '../../remote/activitypub/resolve-person'; -export default ({ data }, done) => (async () => { +export default async ({ data }) => { const keyIdLower = data.signature.keyId.toLowerCase(); let user; @@ -35,4 +35,4 @@ export default ({ data }, done) => (async () => { } await act(user, data.inbox, true); -})().then(done, done); +}; diff --git a/src/processor/http/report-github-failure.ts b/src/processor/http/report-github-failure.ts index 53924a0fbd..4f6f5ccee5 100644 --- a/src/processor/http/report-github-failure.ts +++ b/src/processor/http/report-github-failure.ts @@ -1,29 +1,24 @@ -import * as request from 'request'; +import * as request from 'request-promise-native'; import User from '../../models/user'; const createPost = require('../../server/api/endpoints/posts/create'); -export default ({ data }, done) => { +export default async ({ data }) => { const asyncBot = User.findOne({ _id: data.userId }); // Fetch parent status - request({ + const parentStatuses = await request({ url: `${data.parentUrl}/statuses`, headers: { 'User-Agent': 'misskey' - } - }, async (err, res, body) => { - if (err) { - console.error(err); - return; - } - const parentStatuses = JSON.parse(body); - const parentState = parentStatuses[0].state; - const stillFailed = parentState == 'failure' || parentState == 'error'; - const text = stillFailed ? - `**⚠️BUILD STILL FAILED⚠️**: ?[${data.message}](${data.htmlUrl})` : - `**🚨BUILD FAILED🚨**: →→→?[${data.message}](${data.htmlUrl})←←←`; - - createPost({ text }, await asyncBot); - done(); + }, + json: true }); + + const parentState = parentStatuses[0].state; + const stillFailed = parentState == 'failure' || parentState == 'error'; + const text = stillFailed ? + `**⚠️BUILD STILL FAILED⚠️**: ?[${data.message}](${data.htmlUrl})` : + `**🚨BUILD FAILED🚨**: →→→?[${data.message}](${data.htmlUrl})←←←`; + + createPost({ text }, await asyncBot); };