server: do AP sent statistics in request function
This commit is contained in:
parent
180a1c968d
commit
2164fda2fb
2 changed files with 31 additions and 17 deletions
|
@ -4,7 +4,6 @@ import { request } from '@/remote/activitypub/request.js';
|
|||
import { registerOrFetchInstanceDoc } from '@/services/register-or-fetch-instance-doc.js';
|
||||
import Logger from '@/services/logger.js';
|
||||
import { Instances } from '@/models/index.js';
|
||||
import { apRequestChart, federationChart, instanceChart } from '@/services/chart/index.js';
|
||||
import { fetchInstanceMetadata } from '@/services/fetch-instance-metadata.js';
|
||||
import { toPuny } from '@/misc/convert-host.js';
|
||||
import { StatusError } from '@/misc/fetch.js';
|
||||
|
@ -38,10 +37,6 @@ export default async (job: Bull.Job<DeliverJobData>) => {
|
|||
});
|
||||
|
||||
fetchInstanceMetadata(i);
|
||||
|
||||
instanceChart.requestSent(i.host, true);
|
||||
apRequestChart.deliverSucc();
|
||||
federationChart.deliverd(i.host, true);
|
||||
});
|
||||
|
||||
return 'Success';
|
||||
|
@ -53,10 +48,6 @@ export default async (job: Bull.Job<DeliverJobData>) => {
|
|||
latestStatus: res instanceof StatusError ? res.statusCode : null,
|
||||
isNotResponding: true,
|
||||
});
|
||||
|
||||
instanceChart.requestSent(i.host, false);
|
||||
apRequestChart.deliverFail();
|
||||
federationChart.deliverd(i.host, false);
|
||||
});
|
||||
|
||||
if (res instanceof StatusError) {
|
||||
|
|
|
@ -4,7 +4,16 @@ import { getUserKeypair } from '@/misc/keypair-store.js';
|
|||
import { User } from '@/models/entities/user.js';
|
||||
import { getResponse } from '@/misc/fetch.js';
|
||||
import { createSignedPost, createSignedGet } from './ap-request.js';
|
||||
import { apRequestChart, federationChart, instanceChart } from '@/services/chart/index.js';
|
||||
|
||||
/**
|
||||
* Post an activity to an inbox. Automatically updates the statistics
|
||||
* on succeeded or failed delivery attempts.
|
||||
*
|
||||
* @param user http-signature user
|
||||
* @param url The URL of the inbox.
|
||||
* @param object The Activity or other object to be posted to the inbox.
|
||||
*/
|
||||
export async function request(user: { id: User['id'] }, url: string, object: any): Promise<void> {
|
||||
const body = JSON.stringify(object);
|
||||
|
||||
|
@ -22,14 +31,28 @@ export async function request(user: { id: User['id'] }, url: string, object: any
|
|||
},
|
||||
});
|
||||
|
||||
await getResponse({
|
||||
url,
|
||||
method: req.request.method,
|
||||
headers: req.request.headers,
|
||||
body,
|
||||
// don't allow redirects on the inbox
|
||||
redirect: 'error',
|
||||
});
|
||||
const { host } = new URL(url);
|
||||
|
||||
try {
|
||||
await getResponse({
|
||||
url,
|
||||
method: req.request.method,
|
||||
headers: req.request.headers,
|
||||
body,
|
||||
// don't allow redirects on the inbox
|
||||
redirect: 'error',
|
||||
});
|
||||
|
||||
instanceChart.requestSent(host, true);
|
||||
apRequestChart.deliverSucc();
|
||||
federationChart.deliverd(host, true);
|
||||
} catch (err) {
|
||||
instanceChart.requestSent(host, false);
|
||||
apRequestChart.deliverFail();
|
||||
federationChart.deliverd(host, false);
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue