alpha
Login
or
Join now
nandi.uk
/
semble
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
weekly margin sync (dev only)
author
Wesley Finck
date
4 months ago
(Mar 9, 2026, 1:48 PM -0700)
commit
b274aeb9
b274aeb9c67d600b2af7d914270b86c273388e65
parent
f19ece7c
f19ece7c384e9fbe4df3a5b28a654150fbd97811
+40
-7
1 changed file
Expand all
Collapse all
Unified
Split
src
modules
sync
application
useCases
SyncAccountDataUseCase.ts
+40
-7
src/modules/sync/application/useCases/SyncAccountDataUseCase.ts
View file
Reviewed
···
16
16
} from 'src/shared/infrastructure/config/EnvironmentConfigService';
17
17
import { IAtUriResolutionService } from '../../../cards/domain/services/IAtUriResolutionService';
18
18
19
19
+
// Resync interval: 7 days in milliseconds
20
20
+
const RESYNC_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000;
21
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
79
-
if (existingSyncStatus && existingSyncStatus.syncState.isCompleted()) {
80
80
-
console.log(
81
81
-
`[SYNC] User ${request.curatorId} has already been synced, skipping`,
82
82
-
);
83
83
-
return ok(undefined);
84
84
-
}
85
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
88
+
}
89
89
+
90
90
+
// Check if already synced - environment-aware behavior
91
91
+
if (existingSyncStatus && existingSyncStatus.syncState.isCompleted()) {
92
92
+
const environment = envConfig.get().environment;
93
93
+
94
94
+
// In production, never auto-resync
95
95
+
if (environment === Environment.PROD) {
96
96
+
console.log(
97
97
+
`[SYNC] User ${request.curatorId} has already been synced, skipping (PROD)`,
98
98
+
);
99
99
+
return ok(undefined);
100
100
+
}
101
101
+
102
102
+
// In dev/local, check if resync is needed based on time
103
103
+
const lastSyncedAt = existingSyncStatus.lastSyncedAt;
104
104
+
if (lastSyncedAt) {
105
105
+
const timeSinceLastSync = Date.now() - lastSyncedAt.getTime();
106
106
+
const daysSinceLastSync = Math.floor(
107
107
+
timeSinceLastSync / (24 * 60 * 60 * 1000),
108
108
+
);
109
109
+
110
110
+
if (timeSinceLastSync < RESYNC_INTERVAL_MS) {
111
111
+
console.log(
112
112
+
`[SYNC] User ${request.curatorId} was synced ${daysSinceLastSync} days ago, skipping (${environment})`,
113
113
+
);
114
114
+
return ok(undefined);
115
115
+
}
116
116
+
117
117
+
console.log(
118
118
+
`[SYNC] User ${request.curatorId} was synced ${daysSinceLastSync} days ago, triggering resync (${environment})`,
119
119
+
);
120
120
+
} else {
121
121
+
console.log(
122
122
+
`[SYNC] User ${request.curatorId} has no lastSyncedAt timestamp, triggering resync (${environment})`,
123
123
+
);
124
124
+
}
92
125
}
93
126
94
127
// only listen for test account in local env