68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
'use strict'
|
|
|
|
const { createJsonExportDualHealMixin } = require('pearcord-json-export-mixin')
|
|
|
|
const digestJsonMixin = Object.assign(
|
|
createJsonExportDualHealMixin({
|
|
gossipEntries: [
|
|
{
|
|
method: '_shouldGossipHookFailureDigestJson',
|
|
gossipHashPrefix: '',
|
|
keysField: '_hookFailureDigestJsonGossipKeys',
|
|
initMethod: '_initDigestJsonMixinState'
|
|
}
|
|
],
|
|
heals: [
|
|
{
|
|
watermarkField: '_digestJsonHealWatermark',
|
|
shouldGossipMethod: '_shouldGossipHookFailureDigestJson',
|
|
healMethod: '_healHookFailureDigestJsonCursorOnPartition',
|
|
spanKind: 'digest.json',
|
|
healContext: 'heal.export',
|
|
countField: 'guildDigestJsonCount',
|
|
bridgeKind: 'digest.json',
|
|
listExportsMethod: 'listHookFailureDigestJsonExports'
|
|
}
|
|
]
|
|
}),
|
|
{
|
|
_complianceSnapshotHealWatermark: null,
|
|
|
|
async _healComplianceSnapshotCursorOnPartition (guildId) {
|
|
const gid = guildId || this.guild?.guild?.id || null
|
|
const span = this.log.time('digest.json', {
|
|
spanKind: 'digest.json',
|
|
guildId: gid,
|
|
context: 'heal.compliance'
|
|
})
|
|
try {
|
|
if (!gid) {
|
|
span.end({ relisted: 0, skipped: true, guildDigestJsonCount: 0 })
|
|
return { relisted: 0, skipped: true }
|
|
}
|
|
const watermark = Date.now()
|
|
this._complianceSnapshotHealWatermark = watermark
|
|
const snap = this._lastComplianceSnapshot || null
|
|
span.end({
|
|
relisted: snap ? 1 : 0,
|
|
watermark,
|
|
guildDigestJsonCount: 0,
|
|
entryCount: snap?.count || 0,
|
|
bridgeKind: 'digest.json'
|
|
})
|
|
return { relisted: snap ? 1 : 0, watermark, entryCount: snap?.count || 0 }
|
|
} catch (err) {
|
|
this.log.error('digest.json error', {
|
|
guildId: gid,
|
|
context: 'heal.compliance',
|
|
error: err?.message || String(err)
|
|
})
|
|
span.fail(err)
|
|
return { relisted: 0, error: err?.message || String(err) }
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
module.exports = { digestJsonMixin }
|