Files
HealthLog/src/lib/logging/background.ts
T
Marc-André Bombeck 1f4ba5939d style: apply prettier across the tree
One-shot prettier pass so the new format:check gate starts from a clean
baseline. Formatting only — no behaviour change. Generator-owned and
vendored artifacts stay untouched via .prettierignore.
2026-06-19 22:20:31 +02:00

35 lines
963 B
TypeScript

import { WideEventBuilder } from "./event-builder";
import { eventStorage } from "./context";
import { emitIfSampled } from "./transports";
/**
* Hintergrundaufgabe mit Wide-Event-Logging ausfuehren.
*
* Beispiel:
* await withBackgroundEvent("scheduler.tick", async (evt) => {
* const results = await sendDailyReminders(currentTime);
* evt.setBackground({ task_name: "scheduler.tick", result: results });
* });
*/
export async function withBackgroundEvent<T>(
taskName: string,
fn: (evt: WideEventBuilder) => Promise<T>,
): Promise<T> {
const evt = new WideEventBuilder("background");
evt.setBackground({ task_name: taskName });
return eventStorage.run(evt, async () => {
try {
const result = await fn(evt);
evt.finish();
emitIfSampled(evt.toJSON());
return result;
} catch (error) {
evt.setError(error);
evt.finish();
emitIfSampled(evt.toJSON());
throw error;
}
});
}