mirror of https://codeberg.org/pzp/pzp-gc.git
improve debug logs
This commit is contained in:
parent
198b4be8e9
commit
eca1e5428d
24
lib/index.js
24
lib/index.js
|
@ -32,6 +32,18 @@ function initGC(peer, config) {
|
||||||
let stopMonitoringLogSize = /** @type {CallableFunction | null} */ (null)
|
let stopMonitoringLogSize = /** @type {CallableFunction | null} */ (null)
|
||||||
let hasCleanupScheduled = false
|
let hasCleanupScheduled = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Error} err
|
||||||
|
*/
|
||||||
|
function flattenCauseChain(err) {
|
||||||
|
let str = ''
|
||||||
|
while (err?.message ?? err) {
|
||||||
|
str += (err.message ?? err) + ': '
|
||||||
|
err = /**@type {Error}*/ (err.cause)
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes messages that don't correspond to any goal.
|
* Deletes messages that don't correspond to any goal.
|
||||||
* @private
|
* @private
|
||||||
|
@ -40,12 +52,15 @@ function initGC(peer, config) {
|
||||||
function cleanup(cb) {
|
function cleanup(cb) {
|
||||||
debug('Cleanup started')
|
debug('Cleanup started')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
const done = multicb({ pluck: 1 })
|
const done = multicb({ pluck: 1 })
|
||||||
function makeRecCB(/**@type {string}*/ errorMessage) {
|
|
||||||
|
/**
|
||||||
|
* @param {string} explanation
|
||||||
|
*/
|
||||||
|
function makeRecCB(explanation) {
|
||||||
const cb = done()
|
const cb = done()
|
||||||
return (/**@type {Error=}*/ err) => {
|
return (/**@type {Error=}*/ err) => {
|
||||||
if (err) debug('%s: %s', errorMessage, err.message ?? err)
|
if (err) debug('%s: %s', explanation, flattenCauseChain(err))
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,12 +73,14 @@ function initGC(peer, config) {
|
||||||
if (purpose === 'goal') continue // don't cleanup
|
if (purpose === 'goal') continue // don't cleanup
|
||||||
if (purpose === 'none') {
|
if (purpose === 'none') {
|
||||||
const recCB = makeRecCB('Failed to delete msg when cleaning up')
|
const recCB = makeRecCB('Failed to delete msg when cleaning up')
|
||||||
|
debug('Deleting msg %s with purpose=none', msgID)
|
||||||
peer.db.del(msgID, recCB)
|
peer.db.del(msgID, recCB)
|
||||||
waiting = true
|
waiting = true
|
||||||
} else if (purpose === 'ghost') {
|
} else if (purpose === 'ghost') {
|
||||||
const { tangleID, span } = details
|
const { tangleID, span } = details
|
||||||
const recCB = makeRecCB('Failed to delete ghost msg when cleaning up')
|
const recCB = makeRecCB('Failed to delete ghost msg when cleaning up')
|
||||||
// TODO: Could one msg be a ghostable in MANY tangles? Or just one?
|
// TODO: Could one msg be a ghostable in MANY tangles? Or just one?
|
||||||
|
debug('Deleting and ghosting msg %s with purpose=ghost', msgID)
|
||||||
peer.db.ghosts.add({ tangleID, msgID, span }, (err) => {
|
peer.db.ghosts.add({ tangleID, msgID, span }, (err) => {
|
||||||
if (err) return recCB(err)
|
if (err) return recCB(err)
|
||||||
peer.db.del(msgID, recCB)
|
peer.db.del(msgID, recCB)
|
||||||
|
@ -71,6 +88,7 @@ function initGC(peer, config) {
|
||||||
waiting = true
|
waiting = true
|
||||||
} else if (purpose === 'trail') {
|
} else if (purpose === 'trail') {
|
||||||
const recCB = makeRecCB('Failed to erase trail msg when cleaning up')
|
const recCB = makeRecCB('Failed to erase trail msg when cleaning up')
|
||||||
|
debug('Erasing msg %s with purpose=trail', msgID)
|
||||||
peer.db.erase(msgID, recCB)
|
peer.db.erase(msgID, recCB)
|
||||||
waiting = true
|
waiting = true
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue