feat(client): add digital sync retry details

This commit is contained in:
baiyanyun
2026-06-07 01:17:07 +08:00
parent 0672e82fc7
commit 508406ff10
10 changed files with 230 additions and 140 deletions

View File

@@ -40,6 +40,8 @@ export interface DigitalEmployeeSyncFailure {
operation: string;
attempts: number;
lastAttemptAt: string | null;
nextRetryAt: string | null;
dueForRetry: boolean;
error: string | null;
createdAt: string;
updatedAt: string;
@@ -409,17 +411,32 @@ function readRecentFailures(limit = 3): DigitalEmployeeSyncFailure[] {
updated_at: string;
}>;
return rows.map((row) => ({
id: row.id,
entityType: row.entity_type,
entityId: row.entity_id,
operation: row.operation,
attempts: row.attempts,
lastAttemptAt: row.last_attempt_at,
error: row.error,
createdAt: row.created_at,
updatedAt: row.updated_at,
}));
return rows.map((row) => {
const nextRetryAt = nextRetryAtForFailure(row.last_attempt_at, row.attempts);
return {
id: row.id,
entityType: row.entity_type,
entityId: row.entity_id,
operation: row.operation,
attempts: row.attempts,
lastAttemptAt: row.last_attempt_at,
nextRetryAt,
dueForRetry: !nextRetryAt || Date.now() >= Date.parse(nextRetryAt),
error: row.error,
createdAt: row.created_at,
updatedAt: row.updated_at,
};
});
}
function nextRetryAtForFailure(
lastAttemptAt: string | null,
attempts: number,
): string | null {
if (!lastAttemptAt) return null;
const lastAttemptTime = Date.parse(lastAttemptAt);
if (!Number.isFinite(lastAttemptTime)) return null;
return new Date(lastAttemptTime + retryDelayMs(attempts)).toISOString();
}
function entityTable(entityType: string): string | null {