Refactor: Notify on run completion instead of start

This commit is contained in:
2025-11-06 18:45:26 -08:00
parent 2ec844b766
commit 981e7dc745

View File

@@ -194,7 +194,6 @@ export class MyDurableObject {
this.controller = new AbortController(); this.controller = new AbortController();
await this.saveSnapshot(); await this.saveSnapshot();
this.notify(`Run ${this.rid} started (provider: ${provider || 'openrouter'})`, 3, ['rocket']);
this.state.waitUntil(this.startHeartbeat()); this.state.waitUntil(this.startHeartbeat());
this.state.waitUntil(this.stream({ apiKey, body, provider: provider || 'openrouter' })); this.state.waitUntil(this.stream({ apiKey, body, provider: provider || 'openrouter' }));
} }
@@ -359,7 +358,10 @@ export class MyDurableObject {
} }
async stopHeartbeat() { async stopHeartbeat() {
if (!this.hbActive) return;
this.hbActive = false; 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(() => {}); await this.state.storage.setAlarm(null).catch(() => {});
} }