opencode-statboard 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +16 -5
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -70,13 +70,16 @@ const EXE = (() => {
|
|
|
70
70
|
|
|
71
71
|
let db = null;
|
|
72
72
|
function getDb() {
|
|
73
|
-
if (db) return db;
|
|
74
73
|
if (!Database) return null;
|
|
74
|
+
// Re-open if previous connection was lost (e.g. WAL checkpoint reset).
|
|
75
|
+
if (db) {
|
|
76
|
+
try { db.prepare('SELECT 1').get(); return db; } catch (_) { try { db.close(); } catch (_) {} db = null; }
|
|
77
|
+
}
|
|
75
78
|
if (!fs.existsSync(BACKUP_SRC)) return null;
|
|
76
79
|
try {
|
|
77
80
|
db = new Database(BACKUP_SRC, { readonly: true, fileMustExist: true });
|
|
78
81
|
db.pragma('journal_mode = WAL');
|
|
79
|
-
|
|
82
|
+
db.pragma('busy_timeout = 5000');
|
|
80
83
|
try {
|
|
81
84
|
db.exec("CREATE INDEX IF NOT EXISTS idx_message_time_created ON message(time_created)");
|
|
82
85
|
db.exec("CREATE INDEX IF NOT EXISTS idx_message_session_time ON message(session_id, time_created)");
|
|
@@ -125,6 +128,12 @@ function dbGet(sql, params) {
|
|
|
125
128
|
try { return params ? d.prepare(sql).get(...params) : d.prepare(sql).get(); } catch (_) { return null; }
|
|
126
129
|
}
|
|
127
130
|
|
|
131
|
+
function dbExec(sql) {
|
|
132
|
+
const d = getDb();
|
|
133
|
+
if (!d) return null;
|
|
134
|
+
try { d.exec(sql); return true; } catch (_) { return false; }
|
|
135
|
+
}
|
|
136
|
+
|
|
128
137
|
function ensureIndexes() {
|
|
129
138
|
// Indexes are created inside getDb() on open; kept for explicit warmup call.
|
|
130
139
|
getDb();
|
|
@@ -733,11 +742,13 @@ function gracefulShutdown() {
|
|
|
733
742
|
|
|
734
743
|
process.on('SIGINT', gracefulShutdown);
|
|
735
744
|
process.on('SIGTERM', gracefulShutdown);
|
|
745
|
+
process.on('uncaughtException', (e) => { console.error('uncaught:', e); });
|
|
746
|
+
process.on('unhandledRejection', (e) => { console.error('unhandled:', e); });
|
|
736
747
|
|
|
737
748
|
setInterval(() => {
|
|
738
|
-
cleanExpiredCache(trendCache, TREND_MS * 2);
|
|
739
|
-
cleanExpiredCache(reportCache, REPORT_TTL * 2);
|
|
740
|
-
autoBackupIfDue();
|
|
749
|
+
try { cleanExpiredCache(trendCache, TREND_MS * 2); } catch (_) {}
|
|
750
|
+
try { cleanExpiredCache(reportCache, REPORT_TTL * 2); } catch (_) {}
|
|
751
|
+
try { autoBackupIfDue(); } catch (_) {}
|
|
741
752
|
}, CACHE_CLEANUP_MS);
|
|
742
753
|
|
|
743
754
|
function tryListen(port, maxPort) {
|