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 automationDigestExportSchedule = null
|
||||||
let automationDigestExportSnapshots = []
|
let automationDigestExportSnapshots = []
|
||||||
let auditExportArchives = []
|
let auditExportArchives = []
|
||||||
|
let archivePeerSeen = []
|
||||||
let hookFailureDigest = null
|
let hookFailureDigest = null
|
||||||
await this._initDeliveryReceipts(guild.id)
|
await this._initDeliveryReceipts(guild.id)
|
||||||
if (this.deliveryReceipts) {
|
if (this.deliveryReceipts) {
|
||||||
@@ -1181,6 +1182,7 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
automationDigestExportSnapshots =
|
automationDigestExportSnapshots =
|
||||||
await this.deliveryReceipts.exportAutomationDigestExportSnapshotsSlice(2)
|
await this.deliveryReceipts.exportAutomationDigestExportSnapshotsSlice(2)
|
||||||
auditExportArchives = await this.deliveryReceipts.exportAuditExportArchivesSlice(3)
|
auditExportArchives = await this.deliveryReceipts.exportAuditExportArchivesSlice(3)
|
||||||
|
archivePeerSeen = await this.deliveryReceipts.exportArchivePeerSeenSlice(16)
|
||||||
const digestSnap = await this.deliveryReceipts.getHookFailureDigestSnapshot()
|
const digestSnap = await this.deliveryReceipts.getHookFailureDigestSnapshot()
|
||||||
if (digestSnap) {
|
if (digestSnap) {
|
||||||
hookFailureDigest = {
|
hookFailureDigest = {
|
||||||
@@ -1242,6 +1244,7 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
automationDigestExportSchedule,
|
automationDigestExportSchedule,
|
||||||
automationDigestExportSnapshots,
|
automationDigestExportSnapshots,
|
||||||
auditExportArchives,
|
auditExportArchives,
|
||||||
|
archivePeerSeen,
|
||||||
hookFailureDigest,
|
hookFailureDigest,
|
||||||
workerReleaseHint,
|
workerReleaseHint,
|
||||||
automodConfig: automodConfig
|
automodConfig: automodConfig
|
||||||
@@ -1371,6 +1374,11 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
guildId: payload.guildId
|
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) {
|
if (payload.hookFailureDigest?.digest) {
|
||||||
await this._initDeliveryReceipts(payload.guildId)
|
await this._initDeliveryReceipts(payload.guildId)
|
||||||
await this.deliveryReceipts.ingestHookFailureDigestSlice(
|
await this.deliveryReceipts.ingestHookFailureDigestSlice(
|
||||||
@@ -2196,6 +2204,37 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||||
throw new Error('no permission to fetch automation digest snapshot')
|
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)
|
await this._initDeliveryReceipts(this.guild.guild.id)
|
||||||
let row = await this.deliveryReceipts.getAutomationDigestExportSnapshot(snapshotId)
|
let row = await this.deliveryReceipts.getAutomationDigestExportSnapshot(snapshotId)
|
||||||
if (row?.body?.length) {
|
if (row?.body?.length) {
|
||||||
@@ -2205,8 +2244,7 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
body: row.body,
|
body: row.body,
|
||||||
summaryLines: row.summaryLines,
|
summaryLines: row.summaryLines,
|
||||||
exportedAt: row.exportedAt,
|
exportedAt: row.exportedAt,
|
||||||
fetchMesh: true,
|
fetchAttempt: (Number(opts.attempt) || 0) + 1
|
||||||
fetchAttempts: 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const timeoutMs = Math.min(12000, Math.max(800, Number(opts.timeoutMs) || 3500))
|
const timeoutMs = Math.min(12000, Math.max(800, Number(opts.timeoutMs) || 3500))
|
||||||
@@ -2244,8 +2282,7 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
body: fetched.body,
|
body: fetched.body,
|
||||||
summaryLines: fetched.summaryLines,
|
summaryLines: fetched.summaryLines,
|
||||||
exportedAt: fetched.exportedAt,
|
exportedAt: fetched.exportedAt,
|
||||||
fetchMesh: true,
|
fetchAttempt: (Number(opts.attempt) || 0) + 1
|
||||||
fetchAttempts: 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user