diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-02-07 15:00:44 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-02-07 15:00:44 +0900 |
| commit | 336912e4422394499cb47ea1b8d42cf2020ec93f (patch) | |
| tree | 0bd8c6ef58834a2640ae83b56cb7b70cd756790b /src/queue/processors/http | |
| parent | 10.82.3 (diff) | |
| download | sharkey-336912e4422394499cb47ea1b8d42cf2020ec93f.tar.gz sharkey-336912e4422394499cb47ea1b8d42cf2020ec93f.tar.bz2 sharkey-336912e4422394499cb47ea1b8d42cf2020ec93f.zip | |
Improve instance stats
Diffstat (limited to 'src/queue/processors/http')
| -rw-r--r-- | src/queue/processors/http/deliver.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/queue/processors/http/deliver.ts b/src/queue/processors/http/deliver.ts index d1dad55cd7..cb92a4d760 100644 --- a/src/queue/processors/http/deliver.ts +++ b/src/queue/processors/http/deliver.ts @@ -2,19 +2,43 @@ import * as bq from 'bee-queue'; import request from '../../../remote/activitypub/request'; import { queueLogger } from '../../logger'; +import { registerOrFetchInstanceDoc } from '../../../services/register-or-fetch-instance-doc'; +import Instance from '../../../models/instance'; export default async (job: bq.Job, done: any): Promise<void> => { try { await request(job.data.user, job.data.to, job.data.content); + + // Update stats + registerOrFetchInstanceDoc(job.data.user.host).then(i => { + Instance.update({ _id: i._id }, { + $set: { + latestRequestSentAt: new Date(), + latestStatus: 200 + } + }); + }); + done(); } catch (res) { + // Update stats + registerOrFetchInstanceDoc(job.data.user.host).then(i => { + Instance.update({ _id: i._id }, { + $set: { + latestRequestSentAt: new Date(), + latestStatus: res != null && res.hasOwnProperty('statusCode') ? res.statusCode : null + } + }); + }); + if (res != null && res.hasOwnProperty('statusCode')) { + queueLogger.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`); + if (res.statusCode >= 400 && res.statusCode < 500) { // HTTPステータスコード4xxはクライアントエラーであり、それはつまり // 何回再送しても成功することはないということなのでエラーにはしないでおく done(); } else { - queueLogger.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`); done(res.statusMessage); } } else { |