Compare commits

...

4 Commits

Author SHA1 Message Date
admin 921fbf5cc5 package-loch.json 2026-05-19 14:15:48 +02:00
admin 8ae6734b56 V 1.2.1 source-Feld im POST, Retry bei 429
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 14:13:14 +02:00
admin 0efec3b0cd V 1.2.2 Retry bei 429 für Archive-POSTs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 10:32:50 +02:00
admin 4798e5f9c9 V 1.2.1 source-Feld im POST-Body (loop/archive)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 10:21:19 +02:00
3 changed files with 26 additions and 14 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "wetter_1", "name": "wetter_1",
"version": "1.0.1", "version": "1.2.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "wetter_1", "name": "wetter_1",
"version": "1.0.1", "version": "1.2.1",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"better-sqlite3": "^12.9.0", "better-sqlite3": "^12.9.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "wetter_1", "name": "wetter_1",
"version": "1.2.0", "version": "1.2.1",
"description": "", "description": "",
"license": "ISC", "license": "ISC",
"author": "rxf", "author": "rxf",
+23 -11
View File
@@ -30,18 +30,30 @@ function log(msg) { console.log (`[${fmt24h(new Date())}] ${msg}`); }
function warn(msg) { console.warn(`[${fmt24h(new Date())}] WARN ${msg}`); } function warn(msg) { console.warn(`[${fmt24h(new Date())}] WARN ${msg}`); }
function err(msg) { console.error(`[${fmt24h(new Date())}] ERROR ${msg}`); } function err(msg) { console.error(`[${fmt24h(new Date())}] ERROR ${msg}`); }
function postData(data) { async function postData(data, source) {
if (!POST_URL) return; if (!POST_URL) return;
const headers = { "Content-Type": "application/json" }; const headers = { "Content-Type": "application/json" };
if (COLLECTOR_API_KEY) headers["X-API-Key"] = COLLECTOR_API_KEY; if (COLLECTOR_API_KEY) headers["X-API-Key"] = COLLECTOR_API_KEY;
fetch(POST_URL, { method: "POST", headers, body: JSON.stringify(data) }) const body = JSON.stringify({ ...data, source });
.then(async res => {
if (!res.ok) { for (let attempt = 1; attempt <= 5; attempt++) {
const text = await res.text().catch(() => ""); let res;
warn(`POST ${res.status} ${res.statusText}: ${text.slice(0, 200)}`); try {
} res = await fetch(POST_URL, { method: "POST", headers, body });
}) } catch (e) {
.catch(e => warn("POST fehlgeschlagen: " + e.message)); warn("POST fehlgeschlagen: " + e.message);
return;
}
if (res.ok) return;
if (res.status === 429 && attempt < 5) {
const delay = Number(res.headers.get("Retry-After") ?? 2) * 1000;
await new Promise(r => setTimeout(r, delay));
continue;
}
const text = await res.text().catch(() => "");
warn(`POST ${res.status} ${res.statusText}: ${text.slice(0, 200)}`);
return;
}
} }
// ── 5-Minuten-Aggregation ────────────────────────────────────────────────── // ── 5-Minuten-Aggregation ──────────────────────────────────────────────────
@@ -106,7 +118,7 @@ async function catchUpArchive(db) {
const inserted = insertRecords(db, records, "archive"); const inserted = insertRecords(db, records, "archive");
log(`Archiv: ${inserted} neue Datensätze gespeichert (${records.length} empfangen).`); log(`Archiv: ${inserted} neue Datensätze gespeichert (${records.length} empfangen).`);
for (const r of records) postData(r); for (const r of records) await postData(r, "archive");
} }
// ── LOOP-Schleife ────────────────────────────────────────────────────────── // ── LOOP-Schleife ──────────────────────────────────────────────────────────
@@ -126,7 +138,7 @@ async function runLoop(db) {
const data = await fetchLoopData(station); const data = await fetchLoopData(station);
buffer.push(data); buffer.push(data);
postData(data); postData(data, "loop");
const now = Date.now(); const now = Date.now();
if (now - lastDbWrite >= DB_INTERVAL_MS) { if (now - lastDbWrite >= DB_INTERVAL_MS) {