feat(platform): digest fetch retry and archivePeerSeen guild sync
Refactor fetchAutomationDigestSnapshotFromMesh with exponential backoff retries mirroring audit archives. Bundle archivePeerSeen on GUILD_SYNC push and ingest on join. Phase 107 v0.8.71. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -1171,6 +1171,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
let automationDigestExportSchedule = null
|
||||
let automationDigestExportSnapshots = []
|
||||
let auditExportArchives = []
|
||||
let archivePeerSeen = []
|
||||
let hookFailureDigest = null
|
||||
await this._initDeliveryReceipts(guild.id)
|
||||
if (this.deliveryReceipts) {
|
||||
@@ -1181,6 +1182,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
automationDigestExportSnapshots =
|
||||
await this.deliveryReceipts.exportAutomationDigestExportSnapshotsSlice(2)
|
||||
auditExportArchives = await this.deliveryReceipts.exportAuditExportArchivesSlice(3)
|
||||
archivePeerSeen = await this.deliveryReceipts.exportArchivePeerSeenSlice(16)
|
||||
const digestSnap = await this.deliveryReceipts.getHookFailureDigestSnapshot()
|
||||
if (digestSnap) {
|
||||
hookFailureDigest = {
|
||||
@@ -1242,6 +1244,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
automationDigestExportSchedule,
|
||||
automationDigestExportSnapshots,
|
||||
auditExportArchives,
|
||||
archivePeerSeen,
|
||||
hookFailureDigest,
|
||||
workerReleaseHint,
|
||||
automodConfig: automodConfig
|
||||
@@ -1371,6 +1374,11 @@ class PearcordPlatform extends EventEmitter {
|
||||
guildId: payload.guildId
|
||||
})
|
||||
}
|
||||
for (const seen of payload.archivePeerSeen || []) {
|
||||
if (!seen?.userId) continue
|
||||
await this._initDeliveryReceipts(payload.guildId)
|
||||
await this.deliveryReceipts.ingestArchivePeerSeenRow(payload.guildId, seen)
|
||||
}
|
||||
if (payload.hookFailureDigest?.digest) {
|
||||
await this._initDeliveryReceipts(payload.guildId)
|
||||
await this.deliveryReceipts.ingestHookFailureDigestSlice(
|
||||
@@ -2196,6 +2204,37 @@ class PearcordPlatform extends EventEmitter {
|
||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||
throw new Error('no permission to fetch automation digest snapshot')
|
||||
}
|
||||
const maxAttempts = Math.min(5, Math.max(1, Number(opts.maxAttempts) || 3))
|
||||
const baseDelayMs = Math.max(100, Number(opts.baseDelayMs) || 400)
|
||||
let lastErr = null
|
||||
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
||||
try {
|
||||
const out = await this._fetchAutomationDigestSnapshotFromMeshOnce(snapshotId, {
|
||||
...opts,
|
||||
attempt
|
||||
})
|
||||
return {
|
||||
...out,
|
||||
fetchMesh: true,
|
||||
fetchAttempts: attempt + 1,
|
||||
targetMemberId: opts.targetMemberId || null
|
||||
}
|
||||
} catch (err) {
|
||||
lastErr = err
|
||||
lastErr.fetchAttempts = attempt + 1
|
||||
if (attempt < maxAttempts - 1) {
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, computeArchiveFetchBackoffMs(attempt, baseDelayMs))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
const fail = lastErr || new Error('automation digest snapshot not found on mesh')
|
||||
fail.fetchAttempts = maxAttempts
|
||||
throw fail
|
||||
}
|
||||
|
||||
async _fetchAutomationDigestSnapshotFromMeshOnce (snapshotId, opts = {}) {
|
||||
await this._initDeliveryReceipts(this.guild.guild.id)
|
||||
let row = await this.deliveryReceipts.getAutomationDigestExportSnapshot(snapshotId)
|
||||
if (row?.body?.length) {
|
||||
@@ -2205,8 +2244,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
body: row.body,
|
||||
summaryLines: row.summaryLines,
|
||||
exportedAt: row.exportedAt,
|
||||
fetchMesh: true,
|
||||
fetchAttempts: 1
|
||||
fetchAttempt: (Number(opts.attempt) || 0) + 1
|
||||
}
|
||||
}
|
||||
const timeoutMs = Math.min(12000, Math.max(800, Number(opts.timeoutMs) || 3500))
|
||||
@@ -2244,8 +2282,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
body: fetched.body,
|
||||
summaryLines: fetched.summaryLines,
|
||||
exportedAt: fetched.exportedAt,
|
||||
fetchMesh: true,
|
||||
fetchAttempts: 1
|
||||
fetchAttempt: (Number(opts.attempt) || 0) + 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user