From 981e7dc745ff7a4a73392f912a6450bd8e1f7677 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 6 Nov 2025 18:45:26 -0800 Subject: [PATCH] Refactor: Notify on run completion instead of start --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8907ffe..a1a7cf2 100644 --- a/index.js +++ b/index.js @@ -194,7 +194,6 @@ export class MyDurableObject { this.controller = new AbortController(); await this.saveSnapshot(); - this.notify(`Run ${this.rid} started (provider: ${provider || 'openrouter'})`, 3, ['rocket']); this.state.waitUntil(this.startHeartbeat()); this.state.waitUntil(this.stream({ apiKey, body, provider: provider || 'openrouter' })); } @@ -359,7 +358,10 @@ export class MyDurableObject { } async stopHeartbeat() { + if (!this.hbActive) return; this.hbActive = false; + const ageSeconds = (this.age * HB_INTERVAL_MS) / 1000; + this.notify(`Run ${this.rid} ended. Phase: ${this.phase}. Age: ${ageSeconds.toFixed(1)}s.`, 3, ['stop_sign']); await this.state.storage.setAlarm(null).catch(() => {}); }