groceries: stats page with nightly snapshot (battles, basket, promos, CPI, range)
All checks were successful
Deploy production / deploy (push) Successful in 1m19s
All checks were successful
Deploy production / deploy (push) Successful in 1m19s
This commit is contained in:
14
scripts/groceries-stats.ts
Normal file
14
scripts/groceries-stats.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// Recompute the grocery analytics snapshot (/trackers/groceries/stats) without importing.
|
||||
// bun scripts/groceries-stats.ts
|
||||
// The nightly import (scripts/groceries-import.ts) runs this at the end, under the import lock.
|
||||
import postgres from 'postgres';
|
||||
import { computeStats } from '../src/lib/server/groceries/stats';
|
||||
|
||||
if (!process.env.DB_URL) throw new Error('DB_URL is not set');
|
||||
const log = (m: string) => console.log(`[${new Date().toISOString().slice(11, 19)}Z] ${m}`);
|
||||
const sql = postgres(process.env.DB_URL, { max: 1, connect_timeout: 10, onnotice: () => {} });
|
||||
try {
|
||||
await computeStats(sql, log);
|
||||
} finally {
|
||||
await sql.end();
|
||||
}
|
||||
Reference in New Issue
Block a user