This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

weekly margin sync (dev only)

+40 -7
+40 -7
src/modules/sync/application/useCases/SyncAccountDataUseCase.ts
··· 16 16 } from 'src/shared/infrastructure/config/EnvironmentConfigService'; 17 17 import { IAtUriResolutionService } from '../../../cards/domain/services/IAtUriResolutionService'; 18 18 19 + // Resync interval: 7 days in milliseconds 20 + const RESYNC_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000; 21 + 19 22 export interface SyncAccountDataDTO { 20 23 curatorId: string; 21 24 cardId: string; ··· 76 79 77 80 const existingSyncStatus = syncStatusResult.value; 78 81 79 - if (existingSyncStatus && existingSyncStatus.syncState.isCompleted()) { 80 - console.log( 81 - `[SYNC] User ${request.curatorId} has already been synced, skipping`, 82 - ); 83 - return ok(undefined); 84 - } 85 - 86 82 // Defense in depth: check if another process is already syncing 87 83 if (existingSyncStatus && existingSyncStatus.syncState.isInProgress()) { 88 84 console.log( 89 85 `[SYNC] User ${request.curatorId} sync is already in progress, skipping`, 90 86 ); 91 87 return ok(undefined); 88 + } 89 + 90 + // Check if already synced - environment-aware behavior 91 + if (existingSyncStatus && existingSyncStatus.syncState.isCompleted()) { 92 + const environment = envConfig.get().environment; 93 + 94 + // In production, never auto-resync 95 + if (environment === Environment.PROD) { 96 + console.log( 97 + `[SYNC] User ${request.curatorId} has already been synced, skipping (PROD)`, 98 + ); 99 + return ok(undefined); 100 + } 101 + 102 + // In dev/local, check if resync is needed based on time 103 + const lastSyncedAt = existingSyncStatus.lastSyncedAt; 104 + if (lastSyncedAt) { 105 + const timeSinceLastSync = Date.now() - lastSyncedAt.getTime(); 106 + const daysSinceLastSync = Math.floor( 107 + timeSinceLastSync / (24 * 60 * 60 * 1000), 108 + ); 109 + 110 + if (timeSinceLastSync < RESYNC_INTERVAL_MS) { 111 + console.log( 112 + `[SYNC] User ${request.curatorId} was synced ${daysSinceLastSync} days ago, skipping (${environment})`, 113 + ); 114 + return ok(undefined); 115 + } 116 + 117 + console.log( 118 + `[SYNC] User ${request.curatorId} was synced ${daysSinceLastSync} days ago, triggering resync (${environment})`, 119 + ); 120 + } else { 121 + console.log( 122 + `[SYNC] User ${request.curatorId} has no lastSyncedAt timestamp, triggering resync (${environment})`, 123 + ); 124 + } 92 125 } 93 126 94 127 // only listen for test account in local env