Update job handlers

This commit is contained in:
syuilo 2019-03-08 05:22:14 +09:00
parent 69df556ff5
commit 219570e08b
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 7 additions and 23 deletions

View file

@ -7,7 +7,7 @@ import instanceChart from '../../services/chart/instance';
let latest: string = null; let latest: string = null;
export default async (job: Bull.Job, done: any): Promise<void> => { export default async (job: Bull.Job): Promise<void> => {
const { host } = new URL(job.data.to); const { host } = new URL(job.data.to);
try { try {
@ -29,8 +29,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
instanceChart.requestSent(i.host, true); instanceChart.requestSent(i.host, true);
}); });
done();
} catch (res) { } catch (res) {
// Update stats // Update stats
registerOrFetchInstanceDoc(host).then(i => { registerOrFetchInstanceDoc(host).then(i => {
@ -51,13 +49,12 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
if (res.statusCode >= 400 && res.statusCode < 500) { if (res.statusCode >= 400 && res.statusCode < 500) {
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり // HTTPステータスコード4xxはクライアントエラーであり、それはつまり
// 何回再送しても成功することはないということなのでエラーにはしないでおく // 何回再送しても成功することはないということなのでエラーにはしないでおく
done(); return;
} else {
done(res.statusMessage);
} }
return res.statusMessage;
} else { } else {
queueLogger.warn(`deliver failed: ${res} to=${job.data.to}`); queueLogger.warn(`deliver failed: ${res} to=${job.data.to}`);
done();
} }
} }
}; };

View file

@ -15,7 +15,7 @@ import instanceChart from '../../services/chart/instance';
const logger = new Logger('inbox'); const logger = new Logger('inbox');
// ユーザーのinboxにアクティビティが届いた時の処理 // ユーザーのinboxにアクティビティが届いた時の処理
export default async (job: Bull.Job, done: any): Promise<void> => { export default async (job: Bull.Job): Promise<void> => {
const signature = job.data.signature; const signature = job.data.signature;
const activity = job.data.activity; const activity = job.data.activity;
@ -33,7 +33,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
const { username, host } = parseAcct(keyIdLower.slice('acct:'.length)); const { username, host } = parseAcct(keyIdLower.slice('acct:'.length));
if (host === null) { if (host === null) {
logger.warn(`request was made by local user: @${username}`); logger.warn(`request was made by local user: @${username}`);
done();
return; return;
} }
@ -42,7 +41,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
ValidateActivity(activity, host); ValidateActivity(activity, host);
} catch (e) { } catch (e) {
logger.warn(e.message); logger.warn(e.message);
done();
return; return;
} }
@ -51,7 +49,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
const instance = await Instance.findOne({ host: host.toLowerCase() }); const instance = await Instance.findOne({ host: host.toLowerCase() });
if (instance && instance.isBlocked) { if (instance && instance.isBlocked) {
logger.warn(`Blocked request: ${host}`); logger.warn(`Blocked request: ${host}`);
done();
return; return;
} }
@ -63,7 +60,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
ValidateActivity(activity, host); ValidateActivity(activity, host);
} catch (e) { } catch (e) {
logger.warn(e.message); logger.warn(e.message);
done();
return; return;
} }
@ -72,7 +68,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
const instance = await Instance.findOne({ host: host.toLowerCase() }); const instance = await Instance.findOne({ host: host.toLowerCase() });
if (instance && instance.isBlocked) { if (instance && instance.isBlocked) {
logger.warn(`Blocked request: ${host}`); logger.warn(`Blocked request: ${host}`);
done();
return; return;
} }
@ -92,7 +87,6 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
} else { } else {
updatePerson(activity.actor, null, activity.object); updatePerson(activity.actor, null, activity.object);
} }
done();
return; return;
} }
} }
@ -103,13 +97,11 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
} }
if (user === null) { if (user === null) {
done(new Error('failed to resolve user')); throw new Error('failed to resolve user');
return;
} }
if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) { if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) {
logger.error('signature verification failed'); logger.error('signature verification failed');
done();
return; return;
} }
@ -136,12 +128,7 @@ export default async (job: Bull.Job, done: any): Promise<void> => {
}); });
// アクティビティを処理 // アクティビティを処理
try {
await perform(user, activity); await perform(user, activity);
done();
} catch (e) {
done(e);
}
}; };
/** /**