mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-25 09:43:09 +02:00
Better logs
This commit is contained in:
parent
606e46e4d7
commit
539409faf8
2 changed files with 27 additions and 25 deletions
|
@ -25,25 +25,24 @@ export const deliverQueue = initializeQueue('deliver');
|
||||||
export const inboxQueue = initializeQueue('inbox');
|
export const inboxQueue = initializeQueue('inbox');
|
||||||
export const dbQueue = initializeQueue('db');
|
export const dbQueue = initializeQueue('db');
|
||||||
|
|
||||||
|
const deliverLogger = queueLogger.createSubLogger('deliver');
|
||||||
|
const inboxLogger = queueLogger.createSubLogger('inbox');
|
||||||
|
|
||||||
deliverQueue
|
deliverQueue
|
||||||
.on('waiting', (jobId) => {
|
.on('waiting', (jobId) => deliverLogger.debug(`waiting id=${jobId}`))
|
||||||
queueLogger.debug(`[deliver] waiting id=${jobId}`);
|
.on('active', (job) => deliverLogger.debug(`active id=${job.id} to=${job.data.to}`))
|
||||||
})
|
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`))
|
||||||
.on('active', (job) => {
|
.on('failed', (job, err) => deliverLogger.debug(`failed(${err}) id=${job.id} to=${job.data.to}`))
|
||||||
queueLogger.debug(`[deliver] active id=${job.id} to=${job.data.to}`);
|
.on('error', (error) => deliverLogger.error(`error ${error}`))
|
||||||
})
|
.on('stalled', (job) => deliverLogger.warn(`stalled id=${job.id} to=${job.data.to}`));
|
||||||
.on('completed', (job, result) => {
|
|
||||||
queueLogger.debug(`[deliver] completed(${result}) id=${job.id} to=${job.data.to}`);
|
inboxQueue
|
||||||
})
|
.on('waiting', (jobId) => inboxLogger.debug(`waiting id=${jobId}`))
|
||||||
.on('failed', (job, err) => {
|
.on('active', (job) => inboxLogger.debug(`active id=${job.id} to=${job.data.to}`))
|
||||||
queueLogger.debug(`[deliver] failed(${err}) id=${job.id} to=${job.data.to}`);
|
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`))
|
||||||
})
|
.on('failed', (job, err) => inboxLogger.debug(`failed(${err}) id=${job.id} to=${job.data.to}`))
|
||||||
.on('error', (error) => {
|
.on('error', (error) => inboxLogger.error(`error ${error}`))
|
||||||
queueLogger.error(`[deliver] error ${error}`);
|
.on('stalled', (job) => inboxLogger.warn(`stalled id=${job.id} to=${job.data.to}`));
|
||||||
})
|
|
||||||
.on('stalled', (job) => {
|
|
||||||
queueLogger.warn(`[deliver] stalled id=${job.id} to=${job.data.to}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
export function deliver(user: ILocalUser, content: any, to: any) {
|
export function deliver(user: ILocalUser, content: any, to: any) {
|
||||||
if (content == null) return null;
|
if (content == null) return null;
|
||||||
|
@ -146,12 +145,12 @@ export default function() {
|
||||||
|
|
||||||
export function destroy() {
|
export function destroy() {
|
||||||
deliverQueue.once('cleaned', (jobs, status) => {
|
deliverQueue.once('cleaned', (jobs, status) => {
|
||||||
queueLogger.succ(`[deliver] Cleaned ${jobs.length} ${status} jobs`);
|
deliverLogger.succ(`Cleaned ${jobs.length} ${status} jobs`);
|
||||||
});
|
});
|
||||||
deliverQueue.clean(0, 'wait');
|
deliverQueue.clean(0, 'wait');
|
||||||
|
|
||||||
inboxQueue.once('cleaned', (jobs, status) => {
|
inboxQueue.once('cleaned', (jobs, status) => {
|
||||||
queueLogger.succ(`[inbox] Cleaned ${jobs.length} ${status} jobs`);
|
inboxLogger.succ(`Cleaned ${jobs.length} ${status} jobs`);
|
||||||
});
|
});
|
||||||
inboxQueue.clean(0, 'wait');
|
inboxQueue.clean(0, 'wait');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import * as Bull from 'bull';
|
import * as Bull from 'bull';
|
||||||
import request from '../../remote/activitypub/request';
|
import request from '../../remote/activitypub/request';
|
||||||
import { queueLogger } from '../logger';
|
|
||||||
import { registerOrFetchInstanceDoc } from '../../services/register-or-fetch-instance-doc';
|
import { registerOrFetchInstanceDoc } from '../../services/register-or-fetch-instance-doc';
|
||||||
import Instance from '../../models/instance';
|
import Instance from '../../models/instance';
|
||||||
import instanceChart from '../../services/chart/instance';
|
import instanceChart from '../../services/chart/instance';
|
||||||
|
import Logger from '../../services/logger';
|
||||||
|
|
||||||
|
const logger = new Logger('deliver');
|
||||||
|
|
||||||
let latest: string = null;
|
let latest: string = null;
|
||||||
|
|
||||||
|
@ -11,8 +13,9 @@ export default async (job: Bull.Job) => {
|
||||||
const { host } = new URL(job.data.to);
|
const { host } = new URL(job.data.to);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (latest !== (latest = JSON.stringify(job.data.content, null, 2)))
|
if (latest !== (latest = JSON.stringify(job.data.content, null, 2))) {
|
||||||
queueLogger.debug(`delivering ${latest}`);
|
logger.debug(`delivering ${latest}`);
|
||||||
|
}
|
||||||
|
|
||||||
await request(job.data.user, job.data.to, job.data.content);
|
await request(job.data.user, job.data.to, job.data.content);
|
||||||
|
|
||||||
|
@ -46,7 +49,7 @@ export default async (job: Bull.Job) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res != null && res.hasOwnProperty('statusCode')) {
|
if (res != null && res.hasOwnProperty('statusCode')) {
|
||||||
queueLogger.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`);
|
logger.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`);
|
||||||
|
|
||||||
// 4xx
|
// 4xx
|
||||||
if (res.statusCode >= 400 && res.statusCode < 500) {
|
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||||
|
@ -59,7 +62,7 @@ export default async (job: Bull.Job) => {
|
||||||
throw `${res.statusCode} ${res.statusMessage}`;
|
throw `${res.statusCode} ${res.statusMessage}`;
|
||||||
} else {
|
} else {
|
||||||
// DNS error, socket error, timeout ...
|
// DNS error, socket error, timeout ...
|
||||||
queueLogger.warn(`deliver failed: ${res} to=${job.data.to}`);
|
logger.warn(`deliver failed: ${res} to=${job.data.to}`);
|
||||||
throw res;
|
throw res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue