ework-daemon 0.4.70 → 0.4.71
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/src/op.ts +16 -0
package/package.json
CHANGED
package/src/op.ts
CHANGED
|
@@ -379,6 +379,22 @@ export class Store {
|
|
|
379
379
|
const db = getDB();
|
|
380
380
|
const cutoff = new Date(Date.now() - leaseTtlMs).toISOString();
|
|
381
381
|
|
|
382
|
+
// Identity reuse first: a fast restart (previous heartbeat still fresh)
|
|
383
|
+
// must keep the SAME row/id — daemon_id is embedded in web session links,
|
|
384
|
+
// so a fresh insert per boot orphans every historical link.
|
|
385
|
+
const mine = await db.get<{ id: number }>(
|
|
386
|
+
"SELECT id FROM {{daemons}} WHERE display_name = ? AND internal_endpoint = ? LIMIT 1",
|
|
387
|
+
[displayName, endpoint]
|
|
388
|
+
);
|
|
389
|
+
if (mine) {
|
|
390
|
+
const now = new Date().toISOString();
|
|
391
|
+
const res = await db.run(
|
|
392
|
+
"UPDATE {{daemons}} SET last_heartbeat = ?, status = 'active', capacity = ? WHERE id = ?",
|
|
393
|
+
[now, capacity, mine.id]
|
|
394
|
+
);
|
|
395
|
+
if (res.changes === 1) return mine.id;
|
|
396
|
+
}
|
|
397
|
+
|
|
382
398
|
const orphan = await db.get<{ id: number }>(
|
|
383
399
|
"SELECT id FROM {{daemons}} WHERE last_heartbeat < ? ORDER BY last_heartbeat LIMIT 1",
|
|
384
400
|
[cutoff]
|