forked from mddanishyusuf/traffic-source
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.js
More file actions
27 lines (24 loc) · 1008 Bytes
/
instrumentation.js
File metadata and controls
27 lines (24 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export async function register() {
// Only run on the Node.js server, not during builds or in the browser
if (process.env.NEXT_RUNTIME === 'nodejs') {
const SYNC_INTERVAL = 60 * 1000; // 60 seconds
const runSync = async () => {
try {
const { syncStripePayments } = await import('./src/lib/stripe-sync.js');
const result = await syncStripePayments();
if (result.conversions > 0 || result.refunds > 0) {
console.log(`[Stripe Sync] ${result.conversions} new conversions, ${result.refunds} refunds across ${result.sites} sites`);
}
} catch (err) {
// Don't crash the server — just log and retry next interval
if (!err.message?.includes('no such table')) {
console.error('[Stripe Sync] Error:', err.message);
}
}
};
// Initial sync after a short delay to let the server fully start
setTimeout(runSync, 5000);
// Then sync every 60 seconds
setInterval(runSync, SYNC_INTERVAL);
}
}